9 5 6 7 8 113 1205 199312 199401 201314
Case #1: 5 Case #2: 16 Case #3: 88 Case #4: 352 Case #5: 318505405 Case #6: 391786781 Case #7: 133875314 Case #8: 83347132 Case #9: 16520782
#include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <cmath> #include <algorithm> using namespace std; const double eps = 1e-6; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int MOD = 530600414; #define ll long long #define CL(a) memset(a,0,sizeof(a)) ll ans[300000];//答案 ll c[300000];//c的个数 ll s[300000];//c的坐标和 ll d[300000];//长度 int main() { ans[1]=0; ans[2]=0; ans[3]=1; ans[4]=1; c[4]=1; s[4]=3; d[4]=3; ans[5]=5; c[5]=2; s[5]=7; d[5]=5; ans[6]=16; c[6]=3; s[6]=20; d[6]=8; for(int i=7; i<=201314; i++) { ans[i]=(ans[i-1]+ans[i-2]+(((c[i-2]*d[i-1]-s[i-2])%MOD)*c[i-1])%MOD+(c[i-2]*s[i-1])%MOD)%MOD; c[i]=(c[i-1]+c[i-2])%MOD; s[i]=(s[i-1]+s[i-2]+c[i-1]*d[i-1])%MOD;//第(i-1)个字符串里的c坐标都要加上第(i-2)个串的长度 d[i]=(d[i-1]+d[i-2])%MOD; } int T,n; scanf ("%d",&T); for(int cas=1; cas<=T; cas++) { scanf ("%d",&n); printf ("Case #%d: ",cas); printf ("%lld\n",ans[n]); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/d_x_d/article/details/48626727