hdu--2191--终于可以说出dp水题这句话了-.-

这题是 上一题的 recommend 过来的 很水..

虽然是多重背包 但是 因为数据太小了 完全可以不用二进制拆分去做

我两者都去写了下 ...都是0ms..

 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 const int size = 110;
 7 int weight[size*20];
 8 int val[size*20];
 9 int dp[size];
10
11 int main()
12 {
13     cin.sync_with_stdio(false);
14     int t , n , m , cnt , a , b , c;
15     cin >> t;
16     while(t--)
17     {
18         cin >> n >> m;
19         cnt = 0;
20         memset( dp , 0 , sizeof(dp) );
21         for( int i = 1 ; i<=m ; i++ )
22         {
23             cin >> a >> b >> c;
24             for( int j = 1 ; j<=c ; j<<=1 )
25             {
26                 val[cnt] = j * a;
27                 weight[cnt++] = j*b;
28                 c -= j;
29             }
30             if(c)
31             {
32                 val[cnt] = c*a;
33                 weight[cnt++] = c*b;
34             }
35         }
36         for( int i = 0 ; i<cnt ; i++ )
37         {
38             for( int j = n ; j>=val[i] ; j-- )
39             {
40                 dp[j] = max( dp[j] , dp[ j-val[i] ] + weight[i] );
41             }
42         }
43         cout << dp[n] << endl;
44     }
45     return 0;
46 }

 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 const int size = 110;
 7 int weight[size*20];
 8 int val[size*20];
 9 int dp[size];
10
11 int main()
12 {
13     cin.sync_with_stdio(false);
14     int t , n , m , cnt , a , b , c;
15     cin >> t;
16     while(t--)
17     {
18         cin >> n >> m;
19         cnt = 0;
20         memset( dp , 0 , sizeof(dp) );
21         for( int i = 1 ; i<=m ; i++ )
22         {
23             cin >> a >> b >> c;
24             while(c--)
25             {
26                 weight[cnt] = b;
27                 val[cnt++] = a;
28             }
29         }
30         for( int i = 0 ; i<cnt ; i++ )
31         {
32             for( int j = n ; j>=val[i] ; j-- )
33             {
34                 dp[j] = max( dp[j] , dp[ j-val[i] ] + weight[i] );
35             }
36         }
37         cout << dp[n] << endl;
38     }
39     return 0;
40 }

今天下午 网络赛 我要认真了 -.-

时间: 2024-10-17 23:34:57

hdu--2191--终于可以说出dp水题这句话了-.-的相关文章

HDU 1520 Anniversary party 树DP水题

非常水的树DP,状态为当前为i,上级来没来 然后跑一遍记忆化搜索即可 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib>

HDU 5832 A water problem(某水题)

HDU 5832 A water problem(某水题) Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem Description - 题目描述 Two planets named Haha and Xixi in the universe and they were created with the universe beginning. There is

ACM :漫漫上学路 -DP -水题

CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit Status Description 对于csuxushu来说,能够在CSU(California State University)上学是他一生的荣幸.CSU校园内的道路设计的十分精巧,由n+1条水平道路和n+1条竖直道路等距交错而成,充分体现了校园深厚的文化底蕴.然而不幸的是CS市每到夏季,天降大雨,

Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃圾,大哥拿来了一袋老鼠,其中有w只白老鼠和b只黑老鼠.胡小兔先抓,先抓到白老鼠的人赢. 每次学姐抓完老鼠之后,总会有另外一只老鼠从袋子里自己跑出来(这只老鼠不算任何人抓的),而胡小兔抓老鼠时则不会发生这样的事. 每次袋子里的每只老鼠被抓到的概率相等,当有一只老鼠跑出来的时候,每只老鼠跑出来的几率也相

HDU - 4813 Hard Code (长春赛区水题)

Description Some strange code is sent to Da Shan High School. It's said to be the prophet's note. The note is extremely hard to understand. However, Professor Meng is so smart that he successfully found the pattern of the code. That is, the length of

URAL 1039 Anniversary Party 树形DP 水题

1039. Anniversary Party Time limit: 0.5 secondMemory limit: 8 MB Background The president of the Ural State University is going to make an 80'th Anniversary party. The university has a hierarchical structure of employees; that is, the supervisor rela

hdu 1312 Red and Black(BFS水题)

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9684    Accepted Submission(s): 6021 Problem Description There is a rectangular room, covered with square tiles. Each tile is colore

HDU 2674 N!Again (数论-水题)

N!Again Problem Description WhereIsHeroFrom:             Zty, what are you doing ? Zty:                                     I want to calculate N!...... WhereIsHeroFrom:             So easy! How big N is ? Zty:                                    1 <=

HDU 4143 A Simple Problem(数论-水题)

A Simple Problem Problem Description For a given positive integer n, please find the smallest positive integer x that we can find an integer y such that y^2 = n +x^2. Input The first line is an integer T, which is the the number of cases. Then T line