Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个很猥琐的脑残代码。。

Posted by taozifish at 2011-08-17 20:06:04 on Problem 1351
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator