hdu3732(Steps 3.3.5)
来源:互联网 发布:axure的mac版怎么安装 编辑:程序博客网 时间:2024/04/27 21:47
/*
分析:
多重背包&&二进制。
n最大为10W,容量为1W,所以正常的0-1背包坑定的TLE。
发现0<=v、c<=10,最多有100种组合(而且v==0的10种组
合还不用考虑),所以转化成多重背包就行了。
另外,由于每种组合的情况数可能过多,所以同时还要配
合上二进制的思想(至于这个二进制的思想的话,可以看看
hdu2844这个题:
http://blog.csdn.net/ice_crazy/article/details/8668896)
2013-03-19
*/
分析:
多重背包&&二进制。
n最大为10W,容量为1W,所以正常的0-1背包坑定的TLE。
发现0<=v、c<=10,最多有100种组合(而且v==0的10种组
合还不用考虑),所以转化成多重背包就行了。
另外,由于每种组合的情况数可能过多,所以同时还要配
合上二进制的思想(至于这个二进制的思想的话,可以看看
hdu2844这个题:
http://blog.csdn.net/ice_crazy/article/details/8668896)
2013-03-19
*/
#include"stdio.h"#include"string.h"#include"stdlib.h"const int N=10011;int dp[N];int hash[11][11];int main(){int i,l,j;int n,m;char str[22];int a,b,k,temp;while(scanf("%d%d",&n,&m)!=-1){memset(hash,0,sizeof(hash));for(i=0;i<n;i++){scanf("%s%d%d",str,&a,&b);hash[a][b]++;}memset(dp,0,sizeof(dp));for(i=1;i<11;i++)for(l=0;l<11;l++){if(!hash[i][l])continue;/*****///这部分用二进制k=1;while(hash[i][l]>=k){for(j=m;j>=k*l;j--){temp=dp[j-k*l]+k*i;if(dp[j]<temp)dp[j]=temp;}hash[i][l]-=k;k<<=1;}if(hash[i][l]){k=hash[i][l];for(j=m;j>=k*l;j--){temp=dp[j-k*l]+k*i;if(dp[j]<temp)dp[j]=temp;}}/*****/}printf("%d\n",dp[m]);}return 0;}
- hdu3732(Steps 3.3.5)
- HDU3732
- hdu ACM Steps 3.3
- ACM--steps--3.1.5--
- Steps
- Steps
- Steps
- Steps
- Steps
- Steps
- Steps
- steps
- Steps
- steps
- HDU3732多重背包
- [hdu3732]dp-背包-转换
- ACM--steps--3.3.5--Robberies(01背包)
- hdu acm steps 1.3.5
- 信息安全产品产业化项目资金申请报告编制要点
- Ubuntu 9.0 下之HBase 0.90.4 的安装和使用
- ul和li应用
- junit单元测试(重要)
- C语言作业(2)
- hdu3732(Steps 3.3.5)
- 内存读写
- 关于三元运算符和C#中运行时间的计算
- 关闭显示器
- keytool Commands (SSL)
- Uva - 11401 - Triangle Counting(数学推导)
- 多对一
- java try catch
- substr2