BZOJ2431【一般DP】

用前缀和优化一下就好了.然而暴力是可以过得.

/* I will wait for you*/  
  
#include <cstdio>  
#include <cstdlib>  
#include <cstring>  
#include <cmath>  
#include <ctime>  
#include <algorithm>  
#include <iostream>  
#include <fstream>  
#include <vector>  
#include <queue>  
#include <deque>  
#include <map>  
#include <set>  
#include <string>  
#define make make_pair  
#define fi first  
#define se second  
  
using namespace std;  
  
typedef long long ll;  
typedef unsigned long long ull;  
typedef pair<int,int> pii;  
  
const int maxn = 1010;  
const int maxm = 1010;  
const int maxs = 26;  
const int inf = 0x3f3f3f3f;  
const int P = 10000;  
const double error = 1e-9;  
  
inline int read()  
{  
    int x = 0, f = 1;  
    char ch = getchar();  
    while (ch <= 47 || ch >= 58)  
        f = (ch == 45 ? -1 : 1), ch = getchar();  
    while (ch >= 48 && ch <= 57)  
        x = x * 10 + ch - 48, ch = getchar();  
    return x * f;  
} 

int f[maxn][maxn];

int main()
{
	int n = read(), m = read();
	
	f[0][0] = 1;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			int r = f[i - 1][j];
			int l = j > i - 1 ? f[i - 1][j - i] : 0;
			f[i][j] = (r - l + P) % P;
		}
		for (int j = 1; j <= m; j++)
			(f[i][j] += f[i][j - 1]) %= P;
	}
	
	printf("%d\n", f[n][m]);
	
	return 0;
}


你可能感兴趣的:(BZOJ2431【一般DP】)