当前位置:网站首页>1068 find more coins (30 points)
1068 find more coins (30 points)
2022-07-22 20:34:00 【Konjaku for learning programming】
1068 Find More Coins (30 branch )
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
vector<int> ans;
int dp[10010], v[10010], vis[10010][110];
int main() {
int n, m;
cin >> n >> m;
for(int i = 0; i < n; ++i)
cin >> v[i];
sort(v, v + n, greater<int>());
for(int i = 0; i < n; ++i){
for(int j = m; j >= v[i]; j--){
if(dp[j] <= dp[j - v[i]] + v[i]){
dp[j] = dp[j - v[i]] + v[i];
vis[i][j] = 1;
}
}
}
if(dp[m] != m)
cout << "No Solution";
else{
int i = n;
while(m > 0){
if(vis[i][m]){
ans.push_back(v[i]);
m -= v[i];
}
i--;
}
for(int i = 0; i < ans.size(); ++i)
cout << ans[i] << " \n"[i == ans.size() - 1];
}
}
边栏推荐
猜你喜欢
Kubernetes基础入门
IDEA 隐藏.idea文件夹 隐藏.iml文件
CSDN博客去除上传的图片水印
DETR 论文精读,并解析模型结构
redission看门狗实现机制一看就懂
链栈实现(C语言)
JSON output to file line by line in format
专访Women in AI学者黄惠:绘图形之梦,寻突破之门
Her power series 6 - Yang Di 1: when the girl grows up, she can be good at mathematics and chemistry, and scientific research can be very fresh
Dense Passage Retrieval for Open-Domain Question Answering笔记
随机推荐
她力量系列八丨陈丹琦:我希望女生能够得到更多的机会,男生和女生之间的gap会逐渐不存在的
没有人知道TikTok的最新流行产品Pink Sauce中含有什么成分
AMBert
RAG小结
Pytoch sets different learning rates at different levels
LeetCode160 & LeetCode141——double pointers to solve the linked list
SSM framework integration
Class template parsing
LeetCode0003——longest substring without repeating characters——Sliding Window
const 类型数据的总结
JDBC异常SQLException的捕获与处理
redission扣库存demo
Exclusive interview with Huang Hui, a scholar of women in AI: dream of drawing shapes and find the door to breakthrough
Redis亿级数据存储方案哈希槽分区
7-4 Helping the Couriers (30 分)
7-1 fake news (20 points)
VSCODE 比较两个文件
redission看门狗实现过程详解
LeetCode21——Merge two sorted lists——Iteration or recursion
Mysql连接失败解决方案