当前位置:网站首页>[usaco12mar]cows in a skyscraper g (state compression DP)
[usaco12mar]cows in a skyscraper g (state compression DP)
2022-07-03 07:58:00 【eva_ can(not)survive】
[USACO12MAR]Cows in a Skyscraper G - Luogu https://www.luogu.com.cn/problem/P3052 Continue to learn my state pressure dp, A good question for getting started with shape pressing is to continue to consider the state and the quantity in that state , I found that many questions of state pressure need to record the quantity of this state .
This problem is to record the current state of cattle taking the elevator , Then record the remaining of the last elevator in this state , Then start to think about whether other cows can come in , Or go to the next elevator .
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) ((x)&(-x))
using P = pair<int, int>;
int n, W;
int a[MAXN];
int f[MAXN];
int g[MAXN];
int main() {
int n, W;
scanf("%d %d", &n, &W);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
memset(f, 0x3f, sizeof(f));
f[0] = 1;
g[0] = W;
for (int i = 0; i < (1 << n); i++) {
for (int j = 1; j <= n; j++) {
if (i & 1 << (j - 1))
continue;
if (g[i] >= a[j] && f[i | (1 << (j - 1))] >= f[i]) {
f[i | (1 << (j - 1))] = f[i];
if (f[i | (1 << (j - 1))] == f[i])
g[i | (1 << (j - 1))] = max(g[i | 1 << (j - 1)], g[i] - a[j]);
else
g[i | (1 << (j - 1))] = g[i] - a[j];
} else if (g[i] < a[j] && f[i | (1 << (j - 1))] >= f[i] + 1) {
f[i | (1 << (j - 1))] = f[i] + 1;
if (f[i | (1 << (j - 1))] == f[i] + 1)
g[i | (1 << (j - 1))] = max(g[i | (1 << (j - 1))], W - a[j]);
else
g[i | (1 << (j - 1))] = W - a[j];
}
}
}
printf("%d\n", f[(1 << n) - 1]);
return 0;
}
边栏推荐
- [MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in
- PHP wechat red packet grabbing algorithm
- MAE
- Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
- [global product discovery 2] the first pure cloud augmented reality (AR) platform - Israel
- VMware virtual machine configuration static IP
- Docker installs MySQL and successfully uses Navicat connection
- Introduction of novel RNA based cancer therapies
- Wechat native applet cloud development learning record 01
- Project experience sharing: handwritten Chinese character recognition based on Shengsi mindspire
猜你喜欢
一篇文章让你读懂-曼彻斯特编码
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
Harmonyos third training notes
An article for you to understand - Manchester code
WorldView卫星遥感影像数据/米级分辨率遥感影像
Screenshot tool snipaste
oracle 插入单引号
PostGIS space function
【LeetCode】4. Best time to buy and sell stock
EtherCAT state machine transition (ESM)
随机推荐
idea取消引用顯示效果
Unity2019_ Lighting system
An intern's journey to cnosdb
Install cross compiler arm none liunx gnueabihf
regular expression
An article for you to understand - Manchester code
haproxy+keepalived集群搭建02
PHP常用排序算法
Uniapp learning records
IP production stream is so close to me
Zohocrm deluge function application time verification
Retail philosophy retail psychological warfare after reading -- 7-11 is a good product!
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
Worldview satellite remote sensing image data / meter resolution remote sensing image
MAE
the installer has encountered an unexpected error installing this package
VMware virtual machine configuration static IP
华为S5700交换机初始化和配置telnet,ssh用户方法
JS regular case-
[MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in