当前位置:网站首页>No, no, No. yesterday, someone really didn't write binary enumeration
No, no, No. yesterday, someone really didn't write binary enumeration
2022-07-19 02:31:00 【HYYyyying】
first
What is binary enumeration ???
Click and I will know
Gym Portal
G topic
give n Coins of different values and a total price S, Now choose as many coins as possible to be greater than or equal to S, The requirement is, for example, that the sum of the coins chosen now is sum, Then choose any coin x,sum-x Must be <S.
crap
At first, I tried my best to be greedy ,wawawawawawawawa
Mm-hmm , I'm stupid
This problem is just binary enumeration
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int t, n, s;
int maxx;
const int maxn = 100000;
int a[maxn];
int main(){
scanf("%d", &t);
while(t--){
scanf("%d %d", &n, &s);
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
}
sort(a , a + n);
int sum = 0;
maxx = 0;
bool flag = 0;
int minn = 0x3f3f3f3f;
int cnt = 0;
for(int i = 0; i <= (1 << n) - 1; i++){
sum = 0;
flag = 0;
cnt = 0;
for(int j = 0; j < n; j++){
if(i & (1 << j)){
sum += a[j];
cnt++;
if(!flag){
flag = 1;
minn = a[j];
}
}
}
if(sum - minn < s && sum >= s){
maxx = max(maxx, cnt);
}
}
cout << maxx << endl;
}
return 0;
}```
边栏推荐
猜你喜欢
随机推荐
性能瓶颈定位XMind
[unity development tips] unity packs the EXE on the PC side and compresses and packs it into an EXE file
STL -- string container
How to configure multiple SSH keys for novices (easy to understand hand-in-hand teaching)
逻辑漏洞---登录验证码安全
【Unity开发小技巧】Unity打包PC端exe,压缩打包为一个exe文件
【工具篇】Unity屏幕画线,Unity屏幕画图HSJ绘画工具
STL--map容器
GoReplay
【Unity编辑器扩展】查找场景和资源内挂载某脚本的所有对象
[tools] unity quickly starts to make the artifact tilemap of 2D and 2.5D games
【瑞吉外卖⑩】Linux 粗略学习 & Redis 粗略学习
STL--vector容器
Chapter 2 - system control principle - > classical control theory
SoloPi APP性能测试用
【HDRP高清渲染管道】创建HDRP工程,把内置管线工程升级为HDRP工程
next数组-循环节
php伪协议实现命令执行
性能测试实施规范指南
登录功能的测试点大全








