Too Rich HDU - 5527 (贪心+dfs)
2018-09-01 05:37:57来源:博客园 阅读 ()
Too Rich
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1850 Accepted Submission(s): 480
For example, if p=17 and you have two $10 coins, four $5 coins, and eight $1 coins, you will pay it by two $5 coins and seven $1 coins. But this task is incredibly hard since you are too rich and the sticker is too expensive and pusheen is too lovely, please write a program to calculate the best solution.
1≤T≤20000
0≤p≤109
0≤ci≤100000
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<cstdlib> #include<queue> #include<set> #include<vector> using namespace std; #define INF 0x3f3f3f3f #define eps 1e-10 #define PI acos(-1.0) #define ll long long int const maxn = 1e5+7; const int mod = 1e9 + 7; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int p,ans,c[11]; int val[11]={0,1,5,10,20,50,100,200,500,1000,2000}; ll sum[11]; void dfs(int rest,int idx,int cnt) { if(rest<0) return; if(idx==0) { if(rest==0) ans=max(ans,cnt); return; } ll cur = max(rest-sum[idx-1],(ll)0); int curnum=cur/val[idx]; if(cur % val[idx]) curnum++; if(curnum<=c[idx]) dfs(rest-curnum*val[idx],idx-1,cnt+curnum); curnum++; if(curnum<=c[idx]) dfs(rest-curnum*val[idx],idx-1,cnt+curnum); } int main() { int T; scanf("%d",&T); while(T--) { memset(sum,0,sizeof(sum)); ans=-1; scanf("%d",&p); for(int i=1;i<=10;i++) scanf("%d",&c[i]); for(int i=1;i<=10;i++) sum[i]=sum[i-1]+(ll)(val[i]*c[i]); dfs(p,10,0); printf("%d\n",ans); } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash