【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 ...
随机推荐
- ubuntu16.04spyder闪退
解决办法我试了好用 sudo pip install --upgrade html5lib==.0b8 完事.
- 《深入理解Java虚拟机》读书笔记八
第九章 类加载及执行子系统的案例与实战 Q:如果有10个WEB应用程序都是用Spring来进行组织管理的话,可以把Spring放到Common或Shared目录下(Tomcat5.0)让这些程序共享. ...
- springboot无法查询到后台的数据
问题:springbooot中,整合mybatis时,在IUserMapper接口中, @Select("select * from user where name like '%李%'&q ...
- SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (gb2312_chinese_ci,COERCIBLE) for operation '='
在操作MySQL数据库时,报“ error code [1267]; Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_gen ...
- properties文件读写工具类PropertiesUtil.java
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...
- 解决docker: error pulling image configuration: Get https://registry-1.docker.io/v2/library/mysql/: TLS handshake timeout.
出现这个问题,一般的原因是无法连接到 docker hub,通过: systemctl stop docker echo "DOCKER_OPTS=\"\$DOCKER_OPTS ...
- 爬虫 - Scrapy中间件
前提:看Scrapy架构图 不管什么Middlewares,都写在middlewares.py里面. 然后在settings.py里的DOWNLOADER_MIDDLEWARES或者SPIDER_MI ...
- 如何在JDBC Connection Configuration配置组件上添加控件
如何在JDBC Connection Configuration配置组件上添加控件 最近项目刚上线,闲来无事又把Jmeter的源码拿出来研究研究,最初的目的是想扒一扒Jmeter里数据库处理的逻辑是怎 ...
- wordpress Error establishing a database connection问题
最近这场大雨,快把帝都给淹了,我也快被这不定向问题折磨疯了,本来把项目放在A服务器,nginx ,php7,mysql,然后换到了B服务器,环境一模一样,结果呢,传上去就出现了 哎,话说我的配置也没啥 ...
- SQL语句,pymysql模块,sql注入问题
一.完整版SQL语句的查询 select distinct post,avg(salary) from table where id > 1 group by post` having avg( ...