Computer Transformation

Computer Transformation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9644    Accepted Submission(s): 3624

 
 

Problem Description

A sequence consisting of one digit, the number 1 is initially written into a computer. At each successive time step, the computer simultaneously tranforms each digit 0 into the sequence 1 0 and each digit 1 into the sequence 0 1. So, after the first time step, the sequence 0 1 is obtained; after the second, the sequence 1 0 0 1, after the third, the sequence 0 1 1 0 1 0 0 1 and so on.

How many pairs of consequitive zeroes will appear in the sequence after n steps?

 

Input

Every input line contains one natural number n (0 < n ≤1000).

 

Output

For each input n print the number of consecutive zeroes pairs that will appear in the sequence after n steps.


Sample Input

2

3

Sample Output

1

1

Source

Southeastern Europe 2005

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
const ll mod = 1000000007;
const int N = 5e5 + 5; // 矩阵最大维数
int n;
int a,b;
ll dp1[1005][444]; //0 1串  前一维表示第几次变换,后一维表示可以表示有几位数,即可以表示444位的大整数。
ll dp2[1005][444]; // 1 0串
int main() {
	//dp1[0]=0,dp2[0]=0;
	memset(dp1,0,sizeof(dp1));
	memset(dp2,0,sizeof(dp2));
	rep(i,1,1001){
		int c1=i%2,c2=0;
		for(int j=0;j<444;j++){
			dp1[i][j] = dp1[i-1][j] + dp2[i-1][j] +c1;
			dp2[i][j] = dp1[i-1][j] + dp2[i-1][j] +c2;
			c1 = dp1[i][j]/10, dp1[i][j]%=10 ;
			c2 = dp2[i][j]/10, dp2[i][j]%=10 ;
		}
	}
//	rep(i,0,1001){
//		int j;
//		for(j=443;j>0;j--){
//			if(dp1[i][j]) break;
//		}
//		for(;j>=0;j--){
//			cout<<dp1[i][j];
//		}
//		cout<<'\n';
//	}
	
	while(cin>>n){
		int j;
		for(j=443;j>0;j--){
			if(dp1[n-1][j]) break;
		}
		for(;j>=0;j--){
			cout<<dp1[n-1][j];
		}
		cout<<'\n';
	}
}
发布了46 篇原创文章 · 获赞 81 · 访问量 5558

猜你喜欢

转载自blog.csdn.net/zfq17796515982/article/details/88541606