You live in a small well-planned rectangular town in Phuket. The size of the central area of the town is H kilometers x W kilometers. The central area is divided into HW unit blocks, each of size 1 x 1 km2. There are H + 1 streets going in the West to East direction, and there are W + 1 avenue going in the North-South direction. The central area can be seen as a rectangle on the plane, as shown below.
.jpg)
The first line contains an integer T, the number of test cases (1 <= T <= 5). Each test case is in the following format.
For each test case, for each day, your program must output the number of ways to go to the university modulo 2552 on a separate line. i.e., the output for each test case must contains K lines.
2 2 2 3 1 0 0 0 1 2 1 0 2 0 0 2 1 2 1 1 1 2 1 100 150 2 1 99 150 100 150 2 99 150 100 150 100 149 100 150
3 4 4 1562 0
The amount of I/O for this task is quite large. Therefore, when reading input, you should avoid using java.io.Scanner which is much slower than using java.io.BufferedReader.
#include <cstdio>
#include <cmath>
using namespace std;
const int mod = 2552;
const int MaxN = 1005;
int dp[MaxN][MaxN];
void Init() {
for(int i = 0; i < MaxN; i++)
dp[i][0] = dp[0][i] = 1;
for(int i = 1; i < MaxN; i++)
for(int j = 1; j < MaxN; j++)
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
}
int main() {
int T, w, h, k, q, x, y, xx, yy;
Init();
scanf("%d", &T);
while(T--) {
scanf("%d%d%d", &w, &h, &k);
while(k--) {
scanf("%d", &q);
int ans = dp[w][h];
while(q--) {
scanf("%d%d%d%d", &x, &y, &xx, &yy);
ans = ((ans - dp[x][y] * dp[w - xx][h - yy]) % mod + mod) % mod;
}
printf("%d\n", ans);
}
}
return 0;
}Bnuoj 4275 Your Ways(数学题 + 动态规划)
原文地址:http://blog.csdn.net/lyhvoyage/article/details/45131741