Ox's EOF beef skewer
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 35926 Accepted Submission (s): 16930
Problem Description this year's ACM summer training Team A total of 18 people, divided into 6 teams. There is a team called EOF, consisting of 04 levels of ox, XC, and Level 05 coy. In the common training life, we have established a deep friendship, a cow ready to do something to commemorate the burning years of passion, think, a cow from home brought a fine beef jerky, ready to carve a length of n only by "E" "O" "F" Three characters of a string (can only one or two characters, but absolutely no other characters), the Ox also prohibits the appearance of o adjacent in the string, he thought, "OO" looks like angry eyes, the effect is not good.
You, NEW Acmer,eof's admirer, can help the bull figure out how many different strings meet the requirements.
PS: Ox also has a small secret, is ready to put this engraved with EOF beef dry, as a mysterious gift for Hangzhou Electric 50 Anniversary celebration, can imagine, when the headmaster took this piece of beef dry time how happy. Here, please allow me to express my gratitude to Aniu on behalf of Hangzhou Electric Acmer.
Thanks again.
Input data contains multiple test instances, one row per test instance, and an integer n, (0<n<40).
Output for each test instance, export all of the required coating methods, one row for each instance output.
Sample Input
1 2
Sample Output
3 8 This topic did not think so much at first, in a strange posture godless, using a two-dimensional array to record the state. First of all to tell you my idea, from the topic can be quickly seen, the current string is O, then he only two kinds of row, or there are three kinds of methods. I use a two-dimensional array to record the state F[i][j] (2<=i<=3 && 1<=j<=n) The first dimension I represents is the current number of the previous number is O, if it is 2 (then only two kinds of row), otherwise three, The second dimension of J represents the current length. Then can not see f[3][j]= (f[2][j-1]+f[3][j-1]) * *; F[2][J] = f[3][j-1];
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
LL f[50][50];
void Init () {
f[3][1] = 1;
F[2][2] = 1;
F[2][1] = 0;
F[3][2] = 2;
for (int i = 3; I < i++) {
F[3][i] = (f[2][i-1]+f[3][i-1]);
F[2][i] = f[3][i-1];
}
}
int main () {
Init ();
int n;
while (~SCANF ("%d", &n)) {
printf ("%lld\n", f[3][n]*3+f[2][n]*2);
}
return 0;
}
Of course, there are other things to do, such as the following
#include <iostream>
using namespace std;
int main ()
{
long long a[42];
A[1] = 3;
A[2] = 8;
for (int i=3;i<=40;i++)
a[i]=2* (a[i-1]+a[i-2]);
int n;
while (~SCANF ("%d", &n))
printf ("%lld\n", a[n);
}