-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathTiling problem.cpp
55 lines (51 loc) · 1008 Bytes
/
Tiling problem.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
/*
#include <bits/stdc++.h>
using namespace std;
int replaceTile(long long int m,long long int n,long long int s)
{ if(n<m)
return 1;
s+=replaceTile(m,n-1,s) + replaceTile(m,n-m,s);
return s;}
int main()
{ long long int t;
cin>>t;
while(t--)
{long long int m,n;
cin>>n>>m;
cout <<replaceTile(m,n,0)%1000000007<<"\n";
}return 0;}
*/
#include<iostream>
#include<bits/stdc++.h>
#include<cstring>
#define ll long long
#define MOD 1000000007
using namespace std;
ll compute(ll n, ll m){
// Base Case
int score[n+1];
score[0] = 0;
score[1] = 1;
for(int j=2; j<=n;j++){
// Checks:
if (m>j) {
score[j] = 1;
}
else if (m==j){
score[j] = 2;
}
else {
score[j] = (score[j-m]+score[j-1])%MOD;
}
}
return score[n];
}
int main(){
ll t,n,m;
cin >> t;
for (int i=0;i<t;i++){
cin >> n >> m;
ll ans = compute(n,m);
cout << ans%MOD << endl;
}
}