当前位置:网站首页>[USACO12MAR]Cows in a Skyscraper G(状态压缩dp)
[USACO12MAR]Cows in a Skyscraper G(状态压缩dp)
2022-07-03 07:54:00 【eva_can(not)survive】
[USACO12MAR]Cows in a Skyscraper G - 洛谷https://www.luogu.com.cn/problem/P3052继续学习我的状压dp,一道状压入门好题还是继续考虑状态和该状态下的量,我发现状压的很多题都要记录该状态的量。
这道题就是记录目前牛的坐上电梯的状态,然后记录该状态下最后一班电梯的剩余,然后开始考虑其他牛牛能不能进来,或者是去下一班电梯。
#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;
}边栏推荐
- [at] abc 258G - Triangle 三元组可达-暴力
- Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
- 【cocos creator】点击按钮切换界面
- MAE
- PHP常用排序算法
- 华为交换机Console密码重置、设备初始化、默认密码
- Client server model
- 华为交换机基础配置(telnet/ssh登录)
- Go language foundation ----- 18 ----- collaboration security, mutex lock, read-write lock, anonymous lock, sync Once
- Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition
猜你喜欢

Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function

Oracle queries grouped by time
![[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18](/img/9b/db5fe1a37e0de5ba363f9e108310a5.png)
[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18

Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does

Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation

研究显示乳腺癌细胞更容易在患者睡觉时进入血液

C language learning notes (mind map)

Unity XR实现交互(抓取,移动旋转,传送,射击)-Pico

【LeetCode】3. Merge two sorted lists · merge two ordered linked lists

EtherCAT state machine transition (ESM)
随机推荐
一篇文章让你读懂-曼彻斯特编码
【LeetCode】4. Best time to buy and sell stock
Redis查看客户端连接
【LeetCode】2. Valid Parentheses·有效的括号
Go language foundation ----- 13 ----- file
Structure of golang
Pat grade a 1027 colors in Mars
Huawei switch console password reset, device initialization, default password
How to clear the console password for s7700 device
[MySQL 12] MySQL 8.0.18 reinitialization
Technical dry goods | some thoughts on the future of AI architecture
PAT甲级 1028 List Sorting
【踩坑系列】mysql 修改root密码失败
Redis批量启停脚本
C2-关于VCF文件合并的几种方法
Technical dry goods Shengsi mindspire dynamic transformer with variable sequence length has been released!
PHP常用排序算法
PHP wechat red packet grabbing algorithm
Project experience sharing: handwritten Chinese character recognition based on Shengsi mindspire
[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18