当前位置:网站首页>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;
}```
边栏推荐
- 【Unity编辑器扩展】Unity制作自己的专属的编辑器面板
- Bugku problem solution
- Stl--queue container
- 第二讲 BTC-密码学原理(笔记)
- postman的json脚本转jmeter的jmx脚本
- BeanShell脚本获取当前时间
- 理解 继承、多态、抽象以及它们的概念
- STL -- map container
- [tools] unity2d character controller, which controls 2D players to move and jump in four directions and horizontal directions
- 初识阿里云环境搭建:无法远程连接,入过的坑:服务器ping不通,FTP搭建,服务器搭建数据库,远程连接服务器数据库
猜你喜欢
随机推荐
【工具篇】SQLite本地数据库在Unity3D的应用
ctfhub--ssrf
BeanShell script gets the current time
使用JMeter测试基于WebSocket协议的服务
Simple use case writing specification
find()(名字太多人用我就加字)
JS笔记1
【Unity面板属性扫盲】导入纹理后设置Texture Import Settings
Summary of tree and heap knowledge points
bugku---game1
Experience in using flow playback tool Gor
30分钟搞懂 HTTP 缓存
[unity Editor Extension] unity publishes resources to the store process unity asset store publish
leetcode---每日一题
Software testing technology interim testing summary | software testing foundation & Executive testing & test design and development
[unity panel attribute literacy] set texture import settings after importing textures
bugku----正则匹配,cookies
STL -- string container
Analysis of the paradise of metauniverse developers the ecological value of the metauniverse protocol caduceus
逻辑漏洞---登录验证码安全








