nyoj 蘋果(01背包)

來源:互聯網
上載者:User

標籤:

裸題

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<string> 6 #include<queue> 7 #include<algorithm> 8 #include<map> 9 #include<iomanip>10 #include<climits>11 #include<string.h>12 #include<cmath>13 #include<stdlib.h>14 #include<vector>15 #include<stack>16 #include<set>17 #define INF 1e718 #define MAXN 10001019 #define maxn 100001020 #define Mod 100000721 #define N 101022 using namespace std;23 typedef long long LL;24 25 int T, n, V;26 int dp[N];27 int c[N], w[N];28 29 void run()30 {31     for (int i = 1; i <= n; ++i) {32         cin >> c[i] >> w[i];33     }34     memset(dp, 0, sizeof(dp));35     for (int i = 1; i <= n; ++i)36         for (int j = V; j >= c[i]; --j)37             dp[j] = max(dp[j], dp[j - c[i]] + w[i]);38     cout << dp[V] << endl;39 }40 41 int main()42 {43     while (cin >> n >> V, n+V)44         run();45     //system("pause");46     return 0;47 }
View Code

 

nyoj 蘋果(01背包)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.