2018icpc南京网络赛-E AC Challenge(状压+dfs)
题意:
n道题,每道题有ai和bi,完成这道题需要先完成若干道题,完成这道题可以得到分数t*ai+bi,其中t是时间
1s, n<=20
思路:
由n的范围状压,状态最多1e6
然后dfs,注意代码中dfs里的剪枝,
对一个状态statu,因为贪心的取最大值就行,所以及时剪枝
代码:
当时写不出来真是菜的活该
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const ll Inf = 0x3f3f3f3f3f3f3f3f;
const db pi = acos(-1.0);
int n;
ll dp[maxn];//达到status的最大值
ll a[], b[];
int s[];
vector<int>nd[];
void init(){
for(int i = ; i <= n; i++){
int ans = ;
int sz = nd[i].size();
for(int j = ; j < sz; j++){
ans|=(<<(nd[i][j]-));
}
s[i]=ans;
}
return;
}
void dfs(int cnt, int statu, ll ans){
dp[statu] = max(dp[statu], ans);
if(cnt == n)return;
for(int i = ; i <= n; i++){
if(((<<(i-))&statu)!=)continue;
if((s[i]&statu)!=s[i])continue;
dfs(cnt+,statu|(<<(i-)), ans + (cnt+)*a[i]+b[i]);
}
return;
}
int main(){
mem(dp,-);
scanf("%d", &n);
for(int i = ; i <= n; i++){
int num;
scanf("%lld %lld %d", &a[i], &b[i], &num);
for(int j = ; j < num; j++){
int x;
scanf("%d",&x);
nd[i].pb(x);
}
}
init();
dfs(,,);
printf("%lld",dp[(<<n)-]<?:dp[(<<n)-]);
return ;
} /* */
2018icpc南京网络赛-E AC Challenge(状压+dfs)的更多相关文章
- ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge 状压DP
题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest with n (0 < n \le 20)n(0& ...
- 2018ICPC南京网络赛
2018ICPC南京网络赛 A. An Olympian Math Problem 题目描述:求\(\sum_{i=1}^{n} i\times i! \%n\) solution \[(n-1) \ ...
- 计蒜客 30994 - AC Challenge - [状压DP][2018ICPC南京网络预赛E题]
题目链接:https://nanti.jisuanke.com/t/30994 样例输入: 5 5 6 0 4 5 1 1 3 4 1 2 2 3 1 3 1 2 1 4 样例输出: 55 样例输入: ...
- 2018icpc南京网络赛-L Magical Girl Haze (分层图最短路)
题意: 有向图,可以把k条路的长度变为0,求1到n的最短路 思路: 将图复制k份,一共k+1层图,对于每一条i→j,都连一条低层的i→高层的j,并且权值为0 即对每一对<i,j,w>,都加 ...
- HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)
Walk Through Squares Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Oth ...
- HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)
Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)
Count The Pairs Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)
2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...
- 2019 南京网络赛A
南京网络赛自闭现场 https://nanti.jisuanke.com/t/41298 二维偏序经典题型 二维前缀和!!! #include<bits/stdc++.h> using n ...
随机推荐
- java中一些常考知识
一.static的作用 static是修饰符,用于修饰成员变量(静态变量/类变量). static修饰的成员被所有对象共享. static优先于对象存在. static修饰的成员可以用类名.静态成员来 ...
- Longhorn入门级教程!轻松实现持久化存储!
介 绍 在本文中你将学会如何使用k3s在Civo上运行Longhorn.如果你还没使用过Civo,可以到官网注册(https://www.civo.com/ )还可以申请免费的使用额度.首先,需要一个 ...
- 公司没有 DBA,Mysql 运维自己来
如果你的公司有 DBA,那么我恭喜你,你可以无视 Mysql 运维.如果你的公司没有 DBA,那你就好好学两手 Mysql 基本运维操作,行走江湖,防身必备. 环境:CentOS7 版本: 一.虚拟机 ...
- APP开通支付宝支付 转账功能
注意:支付宝单笔转账到账户功能的准入条件 首先要在商家中心注册,从商家中心可以跳转到开放平台. 登陆蚂蚁金服开放平台 1 开发中心->网页&移动应用 2 根据需求选择应用类型创建应用 3 ...
- 区间dp - 不连续的回文串
Long long ago, there lived two rabbits Tom and Jerry in the forest. On a sunny afternoon, they plann ...
- 《C# 爬虫 破境之道》:第一境 爬虫原理 — 第一节:整体思路
在构建本章节内容的时候,笔者也在想一个问题,究竟什么样的采集器框架,才能算得上是一个“全能”的呢?就我自己以往项目经历而言,可以归纳以下几个大的分类: 根据通讯协议:HTTP的.HTTPS的.TCP的 ...
- play framework 相关
1.下载 官网下载解压,安装有jkd即可使用 2.helloworld $ activator new my-first-app play-java https://www.playframework ...
- 阿里云Centos7.X 如何对外开放端口
一句话:如果你是买的各大厂商的云服务器,去安全组配置对应需要使用到的端口就可以啦! 因为博主用的是阿里云,所以这里就只介绍下阿里云如何开放端口,按着下面三张图来操作就行嘞 这个时候有同学就说了,不通过 ...
- windows命令行(终端)怎么复制粘贴
原文地址:https://jingyan.baidu.com/article/335530daf96f3a19cb41c3f4.html 终端打开后,我们可以简单的ping一下,查看一下连接地址 ...
- 查看jvm内存信息
Runtime.getRuntime().maxMemory(); //最大可用内存,对应-Xmx Runtime.getRuntime().freeMemory(); //当前JVM空闲内存 Run ...