当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

使用百度地图API在地图中设置一个覆盖物(InfoWindow),可自定义窗口内容

文獻調研(三):數據驅動的建築能耗預測模型綜述

Simulation connection between WinCC and STEP7_ Old bear passing by_ Sina blog

详细讲解局部变量、全局变量、静态变量三种类型
![Find the minimum value of flipped array [Abstract bisection]](/img/b9/1e0c6196e6dc51ae2c48f6c5e83289.png)
Find the minimum value of flipped array [Abstract bisection]

DNS复习

line-height小用

Summary of c++ references and pointers

DHCP review

(转载)进程和线程的形象解释
随机推荐
php中使用Makefile编译protobuf协议文件
Network protocol: detailed explanation of redis protocol
[转载]RSLOGIX 5000实例教程
Idea common shortcut keys
Unsigned and signed vernacular
两种块级元素居中的方式
WINCC与STEP7的仿真连接_过路老熊_新浪博客
谈一谈生产环境中swoole协程创建数量控制机制
Raspberry pie sends hotspot for remote login
Stream in PHP socket communication_ Understanding of select method
ASA如何配置端口映射及PAT
Using Google protobuf protocol environment configuration in PHP
关于运行scrapy项目时提示 ModuleNotFoundError: No module named 'pymongo‘的解决方案
文献调研(四):基于case-based reasoning、ANN、PCA的建筑小时用电量预测
Mutual conversion of float type data and datetime type data in sqlserver2008
6. common instructions (upper) v-cloak, v-once, v-pre
MySQL version upgrade + data migration
Talk about singleton mode!
Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
One article explains R & D efficiency! Your concerns are