当前位置:网站首页>[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;
}边栏推荐
- Introduction of novel RNA based cancer therapies
- Go language foundation ----- 03 ----- process control, function, value transfer, reference transfer, defer function
- 【cocos creator】点击按钮切换界面
- Go language foundation ----- 15 ----- reflection
- Precautions for opensips and TLS SIP trunk docking
- HarmonyOS第三次培训笔记
- What is a data type? What is the use of data types?
- *p++、*++p、++*p、(*p)++
- Static keyword
- GoLang之结构体
猜你喜欢

Pat class a 1028 list sorting

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

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

*p++、*++p、++*p、(*p)++

Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task

Go language foundation ----- 11 ----- regular expression

Pat grade a 1029 median

Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
![[untitled]](/img/3d/27a7229e3f0ccf0ca5ae1f00a92513.jpg)
[untitled]

密西根大学张阳教授受聘中国上海交通大学客座教授(图)
随机推荐
Go language foundation ----- 08 ----- interface
LwIP learning socket (API)
Technical dry goods | hundred lines of code to write Bert, Shengsi mindspire ability reward
PIP uses image website to solve the problem of slow network speed
Go language foundation ----- 03 ----- process control, function, value transfer, reference transfer, defer function
一篇文章让你读懂-曼彻斯特编码
MAE
regular expression
Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
PAT甲级 1030 Travel Plan
What is a data type? What is the use of data types?
How to configure GDAL under idea
PHP common sorting algorithm
Docker installs MySQL and successfully uses Navicat connection
Structure of golang
vcs import src < ros2. Repos failed
[untitled]
WorldView卫星遥感影像数据/米级分辨率遥感影像
jsutlis
基于RNA的新型癌症疗法介绍