HDU 46DP 之二(01背包问题)
2018-03-17 12:08
381 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1864
这道题就是都是小数,所以直接扩大100倍。当成正常的背包问题。
这道题就是都是小数,所以直接扩大100倍。当成正常的背包问题。
#include<bits/stdc++.h> #define INF 1e18 #define inf 1e9 #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) using namespace std ; typedef long long ll; typedef unsigned long long ull; const int maxn=3000000+10; int dp[maxn],v[100]; int main() { int n,m,cnt; double a[3],q; while(cin>>q>>n&&n) { cnt=0; while(n--) { memset(a,0,sizeof(a)); char str[10]; cin>>m; double sum=0;bool flag=1; while(m--) { cin>>str; sum+=a[str[0]-'A']+=atof(str+2); if(a[str[0]-'A']>600||sum>1000) flag=0; } if(flag) v[cnt++]=int(100.0*sum); } int dpmax=int(100*q); for(int i=0;i<=dpmax;i++) dp[i]=0; for(int i=0;i<cnt;i++) for(int j=dpmax;j>=v[i];j--) dp[j]=max(dp[j-v[i]]+v[i],dp[j]); cout<<fixed<<showpoint; cout<<setprecision(2)<<dp[dpmax]/100.0<<endl; } }
相关文章推荐
- 01背包及完全背包问题(51Nod - 1085,HDU 1114 Piggy-Bank)
- hdu 1574 RP问题 01背包的变形
- HDU 1574 RP问题(01背包变形)
- HDU 2546 饭卡 【入门DP之01背包问题】
- hdu 1574 RP问题 dp 01背包
- HDU 2191 (01背包问题 13.12.02)
- 陈老师的多校联合20140811||HDU 3236 ||2009年武汉站G题 01背包问题
- HDU 3466 Proud Merchants (01背包排序问题)
- HDU 2955 Robberies(01背包的概率问题)
- hdu 2639 01 背包 存在k 个多解问题
- hdu 2602 Bone Collector (01 背包问题)
- B - Big Event in HDU(背包问题01背包)
- HDU 2955 Robberies(经典01背包概率问题)
- HDU 1203 I NEED A OFFER!(01背包概率问题)
- HDU 3092 Least common multiple 01背包
- hdu 2955 Robberies 01背包问题
- 动态规划经典:01背包问题
- hdu 1114 完全背包 背包问题通俗讲解
- HDU 1171 Big Event in HDU 多重背包01求解
- 01背包问题和完全背包问题 (转载)