【HDOJ】1244 Max Sum Plus Plus Plus

这题目一直wa,原来是因为我把JUDGE写错了,对拍了一下午都没检查出来。水DP啊。

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std; #define MAXN 1020
#define MAXM 35
#define INF 0xfffff int dp[MAXM][MAXN];
int l[MAXM];
int sums[MAXN]; int main() {
int n, m, sum;
int i, j, k, tmp; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif while (scanf("%d",&n)!=EOF && n) {
scanf("%d", &m);
for (i=; i<=m; ++i)
scanf("%d", &l[i]);
sums[] = ;
for (i=; i<=n; ++i) {
scanf("%d", &tmp);
sums[i] = sums[i-] + tmp;
}
sum = ;
memset(dp, , sizeof(dp));
for (i=m; i>; --i) {
sum += l[i];
for (j=n-sum+; j>; --j) {
dp[i][j] = max( dp[i][j+], dp[i+][j+l[i]]+(sums[j+l[i]-]-sums[j-]) );
}
}
printf("%d\n", dp[][]);
} return ;
}
上一篇:【LeetCode】363. Max Sum of Rectangle No Larger Than K 解题报告(Python)


下一篇:CSS样式表、JS脚本加载顺序与SpringMVC在URL路径中传参数与SpringMVC 拦截器