hdu2660
来源:互联网 发布:淘宝设置不包邮地区 编辑:程序博客网 时间:2024/06/05 06:59
Accepted Necklace
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3836 Accepted Submission(s): 1526
For each case, the first line contains two integers N (N <= 20), the total number of stones, and K (K <= N), the exact number of stones to make a necklace.
Then N lines follow, each containing two integers: a (a<=1000), representing the value of each precious stone, and b (b<=1000), its weight.
The last line of each case contains an integer W, the maximum weight my mother will accept, W <= 1000.
1 2 1 1 1 1 1 3
1
AC代码:
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;const int mn=25;const int mw=1005;int ans[mn][mw],v[mn],w[mn];int main(){ int t; scanf("%d",&t); while(t--) { int n,k; scanf("%d%d",&n,&k); for(int i=0;i<n;i++) scanf("%d%d",&v[i],&w[i]); int m; scanf("%d",&m); memset(ans,-1,sizeof(ans)); for(int j=0;j<=mw;j++) ans[0][j]=0; for(int i=0;i<n;i++) { for(int j=m;j>=w[i];j--) for(int l=k;l>0;l--) if(ans[l-1][j-w[i]]+v[i]>ans[l][j]) ans[l][j]=ans[l-1][j-w[i]]+v[i]; } cout<<ans[k][m]<<endl; } return 0;}
- hdu2660
- hdu2660
- hdu2660
- hdu2660
- hdu2660(dfs)
- hdu2660简单DP
- HDU2660:Accepted Necklace(DFS)
- HDU2660 Accepted Necklace
- hdu2660 Accepted Necklace (DFS)
- HDU2660:Accepted Necklace(DFS)
- hdu2660 Accepted Necklace (二维背包)
- hdu2660 Accepted Necklace 二维背包
- hdu2660(Accepted Necklace)-dfs
- hdu2660——Accepted Necklace
- ACM-DFS之Accepted Necklace——hdu2660
- python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multib
- 利用Echarts制作地图(一)
- pid参数整定计算
- 是否二叉搜索树
- 04_Python变量的数据类型
- hdu2660
- git add 与 git commit
- Android studio 依赖冲突的解决
- python 列表字符串字典
- 解决Eclipse Debug 的source not found问题
- Python利用字典实现switch功能
- Django-路由系统
- 【知识库】--spring ApplicationContext 加载配置文件 refresh()(241)
- Head First设计模式--第一章-策略模式