• hihoCoder#1038 01背包


    原题地址

    基本动态规划

    代码:

     1 #include <iostream>
     2 
     3 using namespace std;
     4 
     5 int main() {
     6     int N, M;
     7     int score[100010];
     8     int need[512];
     9     int value[512];
    10 
    11     cin >> N >> M;
    12 
    13     for (int i = 0; i < N; i++)
    14         cin >> need[i] >> value[i];
    15 
    16     for (int i = 0; i <= M; i++)
    17         score[i] = 0;
    18 
    19     for (int i = 0; i < N; i++)
    20         for (int j = M; j >= need[i]; j--)
    21             score[j] = max(score[j], value[i] + score[j - need[i]]);
    22 
    23     cout << score[M] << endl;
    24 
    25     return 0;
    26 }
  • 相关阅读:
    Sky
    MyEclipse 10中文汉化教程
    算法
    查找众数
    格雷码算法
    commons-email
    java
    IO端寻址
    存储器
    汇编顺序程序设计
  • 原文地址:https://www.cnblogs.com/boring09/p/4361274.html
Copyright © 2020-2023  润新知