-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGNYR09.cc
59 lines (53 loc) · 1.05 KB
/
GNYR09.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int dp[100][100][2];
int func(int n, int k, int lb)
{
if(n == 0 && k == 0)
return 1;
else if(n == 0 && k)
return 0;
else if(k == 0)
{
int val = 0;
if(lb == 0)
{
val = func(n-1, k, 1) + func(n-1, k, 0);
}
else
{
val = func(n-1, k, 0);
}
dp[n][k][lb] = val;
return val;
}
if(dp[n][k][lb] != -1)
return dp[n][k][lb];
else
{
int val = 0;
if(lb == 1)
val = func(n-1, k-1, 1) + func(n-1, k, 0);
else
val = func(n-1, k, 0) + func(n-1, k, 1);
dp[n][k][lb] = val;
return val;
}
}
int main()
{
int d;
for(int i = 0; i < 100; ++i)
for(int j = 0 ; j<100; ++j)
dp[i][j][0]=dp[i][j][1]=-1;
cin>>d;
while(d--)
{
int t, n, k;
cin>>t>>n>>k;
cout<< t<<" "<<func(n-1, k, 0) + func(n-1,k,1) << endl;
}
return 0;
}