Title Description
Sedum went to a cave. He had to be here and sister to play with. The cave is a ring, a total of $ $ n-th nodes, he initially $ 0 $ node number, the secondary mobile $ $ I $ I $ he can go to the step in either direction. Because there are other important thing to do, he must go back to $ 0 $ node number after exactly $ m $ times and then leave, and now he wants to know how much the program number, mold $ 1e9 + 7 $. (Two options be considered different, if and only if the position at least after a certain step Sedum where different)
Input Format
Line two integers $ n $, $ m $, meaning If that surface.
Output Format
Line an integer representing the number of analog programs $ 1e9 + 7 $.
Sample
Sample input 1:
4 6
Sample output 1:
0
Sample input 2:
707 185547
Sample Output 2:
588828156
Data range and tips
For $ 20 \% $ data, $ m \ leqslant 20 $.
For $ 60 \% $ data, $ m \ leqslant 1,000 $.
For $ 100 \% $ data, $ m \ leqslant 1e9, n \ leqslant 1,000 $.
answer
This question is the original title meaning of the questions wrong, I am and have been modified.
$ 40 \% $ algorithm:
Direct output $ 0 $ thousand million, and I was shocked actually have many points ~
Time complexity: $ \ Theta (1) $.
Expect Score: $ 0 $ points.
Actual score: $ 40 $ points.
$ 60 \% $ algorithm:
Provided $ dp [i] [j] $ represents the number of program steps to $ $ $ I $ J, then easily can be listed state transition equation: $ dp [i] [j] = dp [i- 1] [ji] + dp [i-1] [j + i] $.
Time complexity: $ \ Theta (n \ times m) $.
Expectations score: $ 60 $ points.
Actual Score: $ 60 $ points (above in the "algorithm" can be sub $ 80 $).
$ 100 \% $ algorithm:
Before we can only find out the pretreatment step $ $ n-case, then treated $ \ left \ lceil \ frac {m} {n} \ right \ rceil $ times by flash power, the $ m \ mod n $ steps further violence finish, time complexity is not allowed? Cyclic matrix wow, can be understood as the emotional push a few steps to the right.
Time complexity: $ \ Theta (n ^ 2 \ times \ log m) $.
期望得分:$100$分。
实际得分:$100$分。
代码时刻
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long dp[1001][1001];
long long wzc[1001],flag[1001],ans[1001];
void matrix1()
{
for(long long i=0;i<n;i++)flag[i]=ans[i],ans[i]=0;
for(long long i=0;i<n;i++)
for(long long j=0;j<n;j++)
ans[(i+j)%n]=(ans[(i+j)%n]+flag[i]*wzc[j]%1000000007)%1000000007;
}
void matrix2()
{
for(long long i=0;i<n;i++)flag[i]=wzc[i],wzc[i]=0;
for(long long i=0;i<n;i++)
for(long long j=0;j<n;j++)
wzc[(i+j)%n]=(wzc[(i+j)%n]+flag[i]*flag[j]%1000000007)%1000000007;
}
int main()
{
scanf("%lld%lld",&n,&m);
dp[0][0]=1;
for(long long i=1;i<=n;i++)
for(long long j=0;j<n;j++)
{
if((j-i+n)%n==(j+i)%n)dp[i][j]=dp[i-1][(j+i)%n];
else dp[i][j]=(dp[i-1][(j-i+n)%n]+dp[i-1][(j+i)%n])%1000000007;
}
for(long long i=0;i<n;i++)
wzc[i]=dp[n][i];
ans[0]=1;
long long bs=m/n;
while(bs)
{
if(bs&1)matrix1();
matrix2();
bs>>=1;
}
bs=m%n;
for(long long i=0;i<n;i++)
dp[0][i]=ans[i];
for(long long i=1;i<=bs;i++)
for(long long j=0;j<n;j++)
{
if((j-i+n)%n==(j+i)%n)dp[i][j]=dp[i-1][(j+i)%n];
else dp[i][j]=(dp[i-1][(j-i+n)%n]+dp[i-1][(j+i)%n])%1000000007;
}
printf("%lld",dp[bs][0]);
return 0;
}
rp++