当前位置:网站首页>P3052 [USACO12MAR]Cows in a Skyscraper G
P3052 [USACO12MAR]Cows in a Skyscraper G
2022-06-26 00:03:00 【AMjieker】
Problem. OJ
The question
give n Items , The volume is w[i], Now they are divided into several groups , The total volume of each group is required <=W, Minimum grouping .(n<=18)
solution
dfs+ Pruning
1, If the current answer exceeds ans It's obviously unreasonable cut off
2, We can choose which one to put in the elevator from big to small Reduce enumeration space ( There is more space to enumerate from small to large Takes longer )
Code
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int N = 22;
int p[N];
int g[N];
int n,m,ans;
void dfs(int k,int t){
if(t>ans) return;
if(k<1){
ans=min(ans,t);return;
}
for(int i=0;i<t;i++){
if(g[k]+p[i]>m) continue;
p[i]+=g[k];
dfs(k-1,t);
p[i]-=g[k];
}
p[t]=g[k];
dfs(k-1,t+1);
p[t]=0;
}
signed main(){
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>g[i];
sort(g+1,g+1+n);
ans = N*N;
dfs(n,1);
cout<<ans<<endl;
return 0;
}
边栏推荐
- Keil compilation run error, missing error: # 5: # includecore_ cm3.h_ Old bear passing by_ Sina blog
- Format the number. If the number is not enough, fill in 0, for example, 1:0001,25:0025
- 对象数组去重
- Recommended system design
- 【微信公众号H5】 生成带参数进入公众号关注页的二维码 监听用户关注公众号事件 自定义菜单栏 (服务端)
- JS中的原型链面试题--Foo和 getName
- 记录一下刷LeetCode瞬间有思路的一道简单题——剑指 Offer 09. 用两个栈实现队列
- Joint simulation of STEP7 and WinCC_ Old bear passing by_ Sina blog
- Studio5k v28安装及破解_过路老熊_新浪博客
- Literature research (IV): Hourly building power consumption prediction based on case-based reasoning, Ann and PCA
猜你喜欢

ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided解决

STEP7主站与远程I/O组网_过路老熊_新浪博客

DHCP review

6. common instructions (upper) v-cloak, v-once, v-pre
![[wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)](/img/d9/935bad29005e5846dc514c966e3b0e.png)
[wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)

Establishment of multiple background blocks in botu software_ Old bear passing by_ Sina blog

Use Baidu map API to set an overlay (infowindow) in the map to customize the window content

postman如何测试需要登录的接口

Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or

手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客
随机推荐
Number array de duplication in JS
Idea common shortcut keys
Literature research (I): hourly energy consumption prediction of office buildings based on integrated learning and energy consumption pattern classification
iomanip头文件在实战中的作用
Common knowledge points in JS
Prototype chain test questions in JS --foo and getname
对伪类的理解
Find the minimum value of flipped array [Abstract bisection]
网络协议之:redis protocol详解
Format the number. If the number is not enough, fill in 0, for example, 1:0001,25:0025
文献调研(二):基于短期能源预测的建筑节能性能定量评估
格式化编号,不够位数的补0,例如1:0001,25:0025
[wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)
Studio5k V28 installation and cracking_ Old bear passing by_ Sina blog
Mutual conversion of float type data and datetime type data in sqlserver2008
Transformation of communication protocol between Siemens S7-200PLC and Danfoss inverter_ Old bear passing by_ Sina blog
用ES5的方式实现const
InputStream流已经关闭了,但是依旧无法delete文件或者文件夹,提示被JVM占用等
Summary of c++ references and pointers
Alipay payment interface sandbox environment test and integration into an SSM e-commerce project