hdu 2126 Buy the souvenirs
来源:互联网 发布:网络极品萝莉 萌小兔 编辑:程序博客网 时间:2024/04/30 03:02
hdu 2126
m元,n种纪念品,求能买最多种数的方法数
#include<stdio.h>#include<string.h>#define maxn 550#define INF 1<<30int dp[maxn][35],n,m,t,flag;int c[35],w[35];int main(){int i,j,k;scanf("%d",&t);while(t--){memset(c,0,sizeof(c));memset(w,1,sizeof(w));memset(dp,0,sizeof(dp));scanf("%d %d",&n,&m);flag=-1;for(i=0;i<n;i++)scanf("%d",&c[i]);for(i=0;i<m;i++){for(j=0;j<=n;j++)dp[i][j]=INF;}//for(j=0;j<=n;j++) //这是错的,因为0元只能买0种物品//dp[0][j]=1;dp[0][0]=1; //起点for(i=0;i<n;i++){for(j=m;j>=c[i];j--) //花j元{for(k=n;k>=1;k--) //买k种{if(dp[j-c[i]][k-1]!=INF){//dp[j][k]=dp[j-c[i]][k-1];if(dp[j][k]==INF) dp[j][k]=dp[j-c[i]][k-1];elsedp[j][k]+=dp[j-c[i]][k-1];if(dp[j][k]!=INF&&k>flag)flag=k; //计最大种数}}}}//printf("flag=%d\n",flag);int s=0; //计组合数for(i=1;i<=m;i++) {if(dp[i][flag]!=INF)s+=dp[i][flag];}if(s==0)printf("Sorry, you can't buy anything.\n");elseprintf("You have %d selection(s) to buy with %d kind(s) of souvenirs.\n",s,flag);}return 0;}
- hdu 2126 Buy the souvenirs
- hdu 2126 Buy the souvenirs
- Buy the souvenirs(hdu(2126)
- HDU 2126 Buy the souvenirs
- HDU 2126 Buy the souvenirs
- HDU 2126 Buy the souvenirs
- hdu 2126 Buy the souvenirs
- HDU - 2126 Buy the souvenirs
- hdu 2126 Buy the souvenirs
- Buy the souvenirs - HDU 2126 背包dp
- HDU 2126 - Buy the souvenirs(01背包)
- HDU-2126 Buy the souvenirs (DP)
- hdu 2126 Buy the souvenirs 01背包
- 2126 Buy the souvenirs
- HDU 2126 Buy the souvenirs (dp 二维01背包)
- hdu 2126 Buy the souvenirs(二维0/1背包)
- HDU 2126 Buy the souvenirs(DP:01背包)
- hdu 2126 Buy the souvenirs(求方案数)
- 冰晶画技术志在何方
- 软命令接口的适用场合
- ibatis sqlMap 中注释引发的问题
- Android_数据存储——SharedPreferences
- Linux 查看历史命令或补全文件名set -o vi/emacs
- hdu 2126 Buy the souvenirs
- SQL语句删除2条重复数据一条保留一条
- java 虚拟登陆
- C#选择文件的对话框控件
- XmlDocument与XmlReader比较
- C#判断IP是否是指定范围内的IP
- SD 学习历程
- tuxedo客户端连接失败解决方法
- 将数据库 二进制流 图片数据 显示出来