-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGNYR09F.cpp
77 lines (70 loc) · 1.35 KB
/
GNYR09F.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
using namespace std;
/*
LEVEL:ROOKIE
Problem Description:
This question is about 3-D Dyanmic Programming.It is the most basic question for newbies to start and learn.
*/
long long arr[101][101][2];
int t,x,y,casex;
void init()
{
int i,b,k;
for(i=0;i<101;i++)
{
for(k=0;k<101;k++)
{
for(b=0;b<2;b++)
{
if(i==0 || i==1)
{
arr[i][k][b]=0;
}
else
{
arr[i][k][b]=-1;
}
}
}
//SDFDS
arr[2][0][1]=1;
arr[2][0][0]=2;
arr[2][1][0]=0;
arr[2][1][1]=1;
}
}
long long solve(int n,int k,int b)
{
if(n<0 || k<0)
{
return 0;
}
else if(arr[n][k][b]!=-1)
{
return arr[n][k][b];
}
else
{
if(b==0)
{
arr[n][k][b]=solve(n-1,k,0)+solve(n-1,k,1);//Recurrence relation for this problem
return arr[n][k][b];
}
else
{
arr[n][k][b]=solve(n-1,k,0)+solve(n-1,k-1,1);
return arr[n][k][b];
}
}
}
int main()
{
cin>>t;
init();
while(t--)
{
cin>>casex>>x>>y;
cout<<casex<<" "<<solve(x,y,0)+solve(x,y,1)<<endl;
}
return 0;
}