-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEuler015.cpp
55 lines (51 loc) · 1019 Bytes
/
Euler015.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 <cmath>
#include <cstdio>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
/*
Contest: ProjectEuler+
Problem #15: Lattice Path
*/
#define mod 1000000007
void Max(int *a,int *b)
{
if(*a<*b)
{
int t;
t=*a;
*a=*b;
*b=t;
}
}
typedef unsigned long long int llu;
llu *grid[1002]={0};
int main() {
int t;
cin>>t;
for(int i=0;i<1002;i++)
{
grid[i]=(llu *)malloc(sizeof(llu)*(i+1));
grid[i][0]=grid[i][i]=1;
grid[i][1]=grid[i][i-1]=i;
//cout<<grid[i][0]<<" ";
if(i>0)
{
for(int j=1;j<i;j++)
{
grid[i][j]=(grid[i-1][j]+grid[i-1][j-1])%mod;
//cout<<grid[i][j]<<" ";
}
}
//cout<<grid[i][i]<<"\n";
}
while(t--)
{
int a,b;
cin>>a>>b;
cout<<grid[a+b][b]<<endl;
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}