Nyoj 252 01 Strings (DP)

Source: Internet
Author: User
Tags min time limit
01 StringsTime limit: Ms | Memory limit: 65535 KB Difficulty: 2 description

ACM's ZYC is studying 01 strings, and he knows the length of some 101 strings, but he wants to know how many 01 strings of this length do not contain the "11" substring, and he wants you to help him.

Note: The length of the 01 string is 2 o'clock, there are 3 kinds: 00,01,10. The input first line has an integer n (0<n<=100), which indicates that there are n sets of test data;
Then there are n rows, each line having an integer m (2<=m<=40), representing the length of the 01 string; The output output does not contain a "11" substring of this length of 01 string total number, one row. Sample input

2
2
3
Sample output
3
5
/*
DP generally by copy ...
time:2014-8-28 1:52
*/ 
#include
<cstdio> #include <cstring>
int dp[100];
void Getdp () {
	dp[2]=3;dp[3]=5;
		for (int i=4;i<=41;i++)
	dp[i]=dp[i-1]+dp[i-2];
}
void Solve () {
	int T;
	Memset (Dp,0,sizeof (DP));
	GETDP ();
	scanf ("%d", &t);
	while (t--) {
		int N;
		
		scanf ("%d", &n);
		printf ("%d\n", Dp[n]);
	}
}
int main () {
	solve ();
return 0;
}         

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.