【PAT甲级】1068 Find More Coins (30 分)(背包/DP)
题意:
输入两个正整数N和M(N<=10000,M<=10000),接着输入N个正整数。输出最小的序列满足序列和为M。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[];
int dp[];
int vis[][];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
for(int i=;i<=n;++i)
cin>>a[i];
sort(a+,a++n);
for(int i=n;i;--i)
for(int j=m;j>=a[i];--j)
if(dp[j]<=dp[j-a[i]]+a[i]){
dp[j]=dp[j-a[i]]+a[i];
vis[i][j]=;
}
if(dp[m]<m)
cout<<"No Solution";
else{
int i=,j=m;
while(){
if(vis[i][j]){
cout<<a[i];
j-=a[i];
if(j)
cout<<" ";
}
++i;
if(!j)
break;
}
}
return ;
}
【PAT甲级】1068 Find More Coins (30 分)(背包/DP)的更多相关文章
- PAT 甲级 1068 Find More Coins (30 分) (dp,01背包问题记录最佳选择方案)***
1068 Find More Coins (30 分) Eva loves to collect coins from all over the universe, including some ...
- PAT甲级1068 Find More Coins【01背包】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805402305150976 题意: n个硬币,每一个有一个特有的价 ...
- PAT 甲级 1068 Find More Coins(0,1背包)
1068. Find More Coins (30) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva l ...
- PAT甲级——1131 Subway Map (30 分)
可以转到我的CSDN查看同样的文章https://blog.csdn.net/weixin_44385565/article/details/89003683 1131 Subway Map (30 ...
- PAT 甲级 1076 Forwards on Weibo (30分)(bfs较简单)
1076 Forwards on Weibo (30分) Weibo is known as the Chinese version of Twitter. One user on Weibo m ...
- PAT 甲级 1045 Favorite Color Stripe (30 分)(思维dp,最长有序子序列)
1045 Favorite Color Stripe (30 分) Eva is trying to make her own color stripe out of a given one. S ...
- PAT 甲级 1018 Public Bike Management (30 分)(dijstra+dfs,dfs记录路径,做了两天)
1018 Public Bike Management (30 分) There is a public bike service in Hangzhou City which provides ...
- PAT 甲级 1014 Waiting in Line (30 分)(queue的使用,模拟题,有个大坑)
1014 Waiting in Line (30 分) Suppose a bank has N windows open for service. There is a yellow line ...
- PAT 甲级 1068 Find More Coins
https://pintia.cn/problem-sets/994805342720868352/problems/994805402305150976 Eva loves to collect c ...
随机推荐
- 滑雪(dfs+dp)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 113903 Accepted: 43478 Description ...
- mybatis报错:A query was run and no Result Maps were found for the Mapped Statement、、Property [login_ip] not found on type [com.thinkgem.jeesite.common.permission.entity.PremissUser]问题解决
今天在做ssm项目的时候出现了: 先是出现 了错误: mybatis报错:A query was run and no Result Maps were found for the Mapped St ...
- 微信小程序 scroll-view 左右横向滑动没有效果(无法滑动)问题
小程序组件 scroll-view 中分别有上下竖向滑动和左右横向滑动之分,在这次项目中刚好需要用到横向滑动,但在测试过程中发现横向滑动没有了效果(静止在那里没移动过),经调试发现: 1.scroll ...
- Elasticsearch系列---shard内部原理
概要 本篇我们来看看shard内部的一些操作原理,了解一下人家是怎么玩的. 倒排索引 倒排索引的结构,是非常适合用来做搜索的,Elasticsearch会为索引的每个index为analyzed的字段 ...
- 自定义ViewPager,避免左右滑动时与水平滑动控件冲突
import android.content.Context;import android.support.v4.view.ViewPager;import android.util.Attribut ...
- 使用webpack搭建vue环境
1.安装node.js,在官网下载,直接下一步,完成.nodejs里默认包含npm环境.国内安装包的速度太慢,建议使用cnpm淘宝镜像. npm install -g cnpm --registry= ...
- 网络常识---tracert
当打不开一个网页,可以是用如下命令查看请求的数据走到哪里了 在命令行中输入“tracert ”并在后面加入一个IP地址,可以查询从本机到该IP地址所在的电脑要经过的路由器及其IP地址
- 跨平台C++ IDE
参考博客:https://blog.csdn.net/m0_37314675/article/details/77881287
- 每天进步一点点------Error: Can't place pins assigned to pin location Pin_K22 (IOPAD_X41_Y19_N14)
在QII中的Assignments----Device----Device and pin option-----(选项卡)Dual purpose pin将nCE0 的设置改为: use as re ...
- MySQL删除语句比较,清空表数据,重置自增长索引
drop truncate delete 程度从强到弱 1.drop table tbdrop将表格直接删除,没有办法找回 2.truncate (table) tbtruncate 删除表中的所有数 ...