Attack on Titans
题意:有三种兵A,B,C,选n个排队,问(至少m个连续的B和至多连续的C)的方案数。
理解了很长时间,,,好菜=_=||
先贴上代码,有空来写
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 const int maxn = 1000010; 5 const int mod = 1000000007; 6 ll d[maxn][4]; 7 ll n,m,k; 8 ll cal(int u){ 9 d[0][0]=1; 10 d[0][1]=0; 11 d[0][2]=0; 12 for(int i=1;i<=n;i++){ 13 ll sum=(d[i-1][0]+d[i-1][1]+d[i-1][2])%mod; 14 d[i][2]=sum; 15 16 if(i<=u) d[i][0]=sum; 17 else if(i==u+1) d[i][0]=(sum-1)%mod; 18 else d[i][0]=(sum-d[i-u-1][1]-d[i-u-1][2])%mod; 19 20 if(i<=k) d[i][1]=sum; 21 else if(i==k+1) d[i][1]=(sum-1)%mod; 22 else d[i][1]=(sum-d[i-1-k][0]-d[i-1-k][2])%mod; 23 } 24 return (d[n][0]+d[n][1]+d[n][2])%mod; 25 } 26 int main(){ 27 while(scanf("%d%d%d",&n,&m,&k)!=EOF){ 28 ll ans=cal(n); 29 ans=((ans-cal(m-1))%mod+mod)%mod; 30 printf("%lld\n",ans); 31 } 32 return 0; 33 }
时间: 2024-11-06 14:14:52