当前位置:网站首页>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;
}
边栏推荐
- Can I upload pictures without deploying the server?
- 利用VBScript连接mysql数据库_过路老熊_新浪博客
- The role of iomanip header file in actual combat
- Transformation of communication protocol between Siemens S7-200PLC and Danfoss inverter_ Old bear passing by_ Sina blog
- 对伪类的理解
- 手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客
- [转载]RSLOGIX 5000实例教程
- Apache doris1.0 cluster setup, load balancing and parameter tuning
- JS中的原型链面试题--Foo和 getName
- Search rotation array ii[Abstract dichotomy exercise]
猜你喜欢
keil编译运行错误,缺少error:#5:#includecore_cm3.h_过路老熊_新浪博客
详细讲解局部变量、全局变量、静态变量三种类型
【微信公众号H5】 生成带参数进入公众号关注页的二维码 监听用户关注公众号事件 自定义菜单栏 (服务端)
Linking MySQL database with visual studio2015 under win10
Connecting MySQL database with VBScript_ Old bear passing by_ Sina blog
unsigned与signed之大白话
SSM integrated learning notes (mainly ideas)
Common problems encountered when creating and publishing packages using NPM
博图软件中多重背景块的建立_过路老熊_新浪博客
mysql5.7版本在配置文件my.ini[mysqld]加上skip-grant-tables后无法启动
随机推荐
Implement const in Es5
The InputStream stream has been closed, but the file or folder cannot be deleted, indicating that it is occupied by the JVM
Object array de duplication
Network protocol: detailed explanation of redis protocol
【微信公众号H5】 生成带参数进入公众号关注页的二维码 监听用户关注公众号事件 自定义菜单栏 (服务端)
手工制作 pl-2303hx 的USB转TTL电平串口的电路_过路老熊_新浪博客
剑指 Offer 48. 最长不含重复字符的子字符串
关于运行scrapy项目时提示 ModuleNotFoundError: No module named 'pymongo‘的解决方案
手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客
unsigned与signed之大白话
Topic36——53. 最大子数组和
Mutual conversion of float type data and datetime type data in sqlserver2008
Doris 运维中遇到的问题
猕猴桃酵素的功效_过路老熊_新浪博客
Redis之内存淘汰机制
7.常用指令(下)v-on,v-bind,v-model的常见操作
《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
Building cloud computers with FRP
huibian
Line height for small use