标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cmath> 5 #include<iostream> 6 #include<algorithm> 7 using namespace std; 8 const int Mod=100000007; 9 int dp[1005][1005]; 10 int main() 11 { 12 int n,s,a,b; 13 scanf("%d%d%d%d",&n,&s,&a,&b); 14 dp[1][0]=1;//不妨设首项为0 15 for(int i=1;i<n;i++) 16 { 17 for(int j=0;j<n;j++) 18 { 19 //计算每一次+a或者-b对数列之和sum的贡献 20 dp[i+1][(j+(n-i)*a)%n]=(dp[i+1][(j+(n-i)*a)%n]+dp[i][j])%Mod; 21 dp[i+1][(j+i*b)%n]=(dp[i+1][(j+i*b)%n]+dp[i][j])%Mod; 22 //等价于dp[i+1][(j-(n-i)*b)%n]+=dp[i][j]; 23 } 24 } 25 s=(s+1000000000LL*n)%n;//保证s非负且不改变s mod n的值 26 printf("%d\n",dp[n][s%n]); 27 //若sum=s(mod n)则可以改变首项使得数列满足条件 28 return 0; 29 }
标签:
原文地址:http://www.cnblogs.com/767355675hutaishi/p/4320348.html