Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴个很猥琐的脑残代码。。#include<iostream> #include<cstdio> #include<cstring> using namespace std; long long s[18][5][4]; void dp(int x){ if(x>=17)return; s[x][1][0]=s[x-1][1][0]; s[x][1][1]=s[x-1][1][1]+s[x-1][2][1]+s[x-1][3][1]; s[x][1][2]=s[x-1][4][0]+s[x-1][4][2]+s[x-1][1][2]; s[x][1][3]=s[x-1][4][1]+s[x-1][1][3]+s[x-1][2][3]+s[x-1][3][3]+s[x-1][4][3]; s[x][2][1]=s[x-1][1][0]+s[x-1][4][0]+s[x-1][1][1]+s[x-1][2][1]+s[x-1][3][1]+s[x-1][4][1]; s[x][2][3]=s[x-1][1][2]+s[x-1][4][2]+s[x-1][1][3]+s[x-1][2][3]+s[x-1][3][3]+s[x-1][4][3]; s[x][3][1]=s[x-1][1][0]+s[x-1][4][0]+s[x-1][1][1]+s[x-1][2][1]+s[x-1][3][1]+s[x-1][4][1]; s[x][3][3]=s[x-1][1][2]+s[x-1][4][2]+s[x-1][1][3]+s[x-1][2][3]+s[x-1][3][3]+s[x-1][4][3]; s[x][4][0]=s[x-1][4][0]; s[x][4][1]=s[x-1][4][1]+s[x-1][2][1]+s[x-1][3][1]; s[x][4][2]=s[x-1][1][0]+s[x-1][1][2]+s[x-1][4][2]; s[x][4][3]=s[x-1][1][1]+s[x-1][1][3]+s[x-1][2][3]+s[x-1][3][3]+s[x-1][4][3]; dp(x+1); } int main(){ int i, n; for(i=1; i<=4; i++){ if(i==1||i==4){ s[1][i][0]=1; s[1][i][1]=0; s[1][i][2]=0; s[1][i][3]=0; } else { s[1][i][0]=0; s[1][i][1]=1; s[1][i][2]=0; s[1][i][3]=0; } } dp(2); while(scanf("%d", &n)&&n>0){ long long ans=0; for(i=1; i<=4; i++)ans+=s[n][i][3]; printf("%d: %lld\n",n, ans); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator