zoukankan      html  css  js  c++  java
  • 【HDOJ】1244 Max Sum Plus Plus Plus

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

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cstdlib>
     4 #include <algorithm>
     5 #include <iostream>
     6 using namespace std;
     7 
     8 #define MAXN 1020
     9 #define MAXM 35
    10 #define INF 0xfffff
    11 
    12 int dp[MAXM][MAXN];
    13 int l[MAXM];
    14 int sums[MAXN];
    15 
    16 int main() {
    17     int n, m, sum;
    18     int i, j, k, tmp;
    19 
    20 #ifndef ONLINE_JUDGE
    21     freopen("data.in", "r", stdin);
    22     freopen("data.out", "w", stdout);
    23 #endif
    24 
    25     while (scanf("%d",&n)!=EOF && n) {
    26         scanf("%d", &m);
    27         for (i=1; i<=m; ++i)
    28             scanf("%d", &l[i]);
    29         sums[0] = 0;
    30         for (i=1; i<=n; ++i) {
    31             scanf("%d", &tmp);
    32             sums[i] = sums[i-1] + tmp;
    33         }
    34         sum = 0;
    35         memset(dp, 0, sizeof(dp));
    36         for (i=m; i>0; --i) {
    37             sum += l[i];
    38             for (j=n-sum+1; j>0; --j) {
    39                 dp[i][j] = max( dp[i][j+1], dp[i+1][j+l[i]]+(sums[j+l[i]-1]-sums[j-1]) );
    40             }
    41         }
    42         printf("%d
    ", dp[1][1]);
    43     }
    44 
    45     return 0;
    46 }
  • 相关阅读:
    three.js详解
    Javascript的原型
    Transform? Transition? Animation?
    Backbone源码分析Backbone架构+流程图
    对象是引用的注意原型中的属性改变
    MySQL+ JSP+Tomcat開發指引
    MySQL應用分析
    SQL 日期
    MySQL安裝
    MSE错误应对分享
  • 原文地址:https://www.cnblogs.com/bombe1013/p/4087465.html
Copyright © 2011-2022 走看看