zoukankan      html  css  js  c++  java
  • 01背包(模板题) 之 poj 3624

    01背包模板题。。。

     1 #include <iostream>
     2 #include <cstdlib>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <algorithm>
     6 using namespace std;
     7 const int MAX = 3410, max_w = 12885;
     8 int N, M;
     9 int W[MAX], D[MAX], dp[max_w];
    10 
    11 int Solve() {
    12     memset(dp, 0, sizeof(dp));
    13     for (int i = 1; i <= N; ++i) {
    14         for (int j = M; j >= W[i]; --j) {
    15             dp[j] = max(dp[j], dp[j - W[i]] + D[i]);
    16         }
    17     }
    18     return dp[M];
    19 }
    20 
    21 int main() {
    22     //freopen("input.txt", "r", stdin);
    23     scanf("%d %d", &N, &M);
    24     for (int i = 1; i <= N; ++i) {
    25         scanf("%d %d", &W[i], &D[i]);
    26     }
    27     printf("%d
    ", Solve());
    28     return 0;
    29 }



  • 相关阅读:
    FastAPI(5)- 查询参数 Query Parameters
    FastAPI(4)- 路径参数 Path Parameters
    FastAPI(3)- uvicorn.run()
    Python
    Python
    Python
    Python
    Python
    Python
    Python
  • 原文地址:https://www.cnblogs.com/shijianming/p/4140829.html
Copyright © 2011-2022 走看看