日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

DP Big Event in HDU

發(fā)布時(shí)間:2024/4/15 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DP Big Event in HDU 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Big Event in HDU

Time Limit : 10000/5000ms (Java/Other)???Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 84???Accepted Submission(s) : 38

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.
The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).

Input

Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --corresponding number of the facilities) each. You can assume that all V are different.
A test case starting with a negative integer terminates input and this test case is not to be processed.

Output

For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.

Sample Input

2 10 1 20 1 3 10 1 20 2 30 1 -1

Sample Output

20 10 40 40 ??題目的意思就是把這些設(shè)備盡量的平分成兩份,先輸出大的,再輸出小的。
? ? ?總價(jià)值(所有v[i]*m[i]之和)的一半作為背包的容量,把每一種中的每一個(gè)設(shè)備都看成一塊石頭。按01背包的解法,打表更新。使答案非常接近總質(zhì)量的一半(就是在不超過總質(zhì)量一半的前提下,dp【k】越大就是越接近)。
? ? ?外面的兩個(gè)循環(huán)就是遍歷每一個(gè)設(shè)備,相當(dāng)于01背包的外循環(huán):for(i=1;i<=石頭的數(shù)量;i++)。最里面的循環(huán)讓容量從sum到v【i】(可以不到0,因?yàn)?到v【i】這部分,放不了任何石頭,不更新,也就不需要判斷v【i】是否大于k了) #include <iostream> #include <algorithm> #include <string> #include <cstring> using namespace std; int main() { int T; int v[55], m[55]; while (cin >> T && T >= 0) { int i; int s = 0; for (i = 1; i <= T; i++) { cin >> v[i] >> m[i]; s = s + v[i] * m[i]; } int sum = s / 2; int dp[250005]; memset(dp, 0, sizeof(dp)); int j; for (i = 1; i <= T; i++)//對(duì)每一種遍歷 { for (j = 1; j <= m[i]; j++)//有幾個(gè)就遍歷幾個(gè) {//把它變成01背包,總共有T*m[i]個(gè)石頭,遍歷 int k; for (k = sum; k >= v[i]; k--)//最小的石頭就是v[i]大,只要到v[i]就可以了 { dp[k] = max(dp[k], dp[k - v[i]] + v[i]); } } } if (dp[sum] > s - dp[sum]) cout << dp[sum] << " " << s - dp[sum] << endl; else cout << s - dp[sum] << " " << dp[sum] << endl; } return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/caiyishuai/p/8325880.html

總結(jié)

以上是生活随笔為你收集整理的DP Big Event in HDU的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。