https://nanti.jisuanke.com/t/30994

题意

给你n个题目,对于每个题目,在做这个题目之前,规定了必须先做哪几个题目,第t个做的题目i得分是t×ai+bi问最终的最大得分是多少?

分析

枚举所有状态,在转移时判断合法性,然后直接转移就好了。dp初始化为-inf,边界值dp[0]=0;

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
#define ne S, T, w, opi acos(-1)
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int maxn = (<<) +;
const int maxm = 1e6 +;
const int mod = ;
int n, m, k;
struct point{
int a,b,k;
int f;
}p[];
ll dp[maxn];
int num[maxn];
int bit[maxn];
int main(){
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n,tmp;
scanf("%d",&n);
for(int i=;i<=n;i++) bit[i]=<<i;
for(int i=;i<(<<n);i++){
num[i]=__builtin_popcount(i);
}
for(int i=;i<n;i++) {
scanf("%d%d%d",&p[i].a,&p[i].b,&p[i].k);
p[i].f=;
for(int j=;j<p[i].k;j++) {
scanf("%d",&tmp);
// p[i].f|=(1<<(tmp-1));
p[i].f|=bit[tmp-];
}
}
ll ans=;
memset(dp,-inf,sizeof(dp));
dp[]=;
for(int i=;i<bit[n];i++){
if(dp[i]==-inf) continue;
ans=max(ans,dp[i]);
for(int j=;j<n;j++){
if(i&bit[j]) continue;
if((i&p[j].f)!=p[j].f) continue;
dp[i|bit[j]]=max(dp[i|bit[j]],dp[i]+1ll*(num[i]+)*p[j].a+p[j].b);
}
}
// cout<<ans<<endl;
printf("%lld\n",ans);
return ;
}

ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge(状压dp)的更多相关文章

  1. 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& ...

  2. ACM-ICPC 2018 南京赛区网络预赛 E. AC Challenge (状态压缩DP)

    Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answe ...

  3. ACM-ICPC 2018 南京赛区网络预赛 J.sum

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  4. ACM-ICPC 2018 南京赛区网络预赛 E题

    ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...

  5. ACM-ICPC 2018 南京赛区网络预赛B

    题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...

  6. 计蒜客 30999.Sum-筛无平方因数的数 (ACM-ICPC 2018 南京赛区网络预赛 J)

    J. Sum 26.87% 1000ms 512000K   A square-free integer is an integer which is indivisible by any squar ...

  7. 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)

    G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K   During tea-drinking, princess, amongst other t ...

  8. 计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)

    A. An Olympian Math Problem 54.28% 1000ms 65536K   Alice, a student of grade 66, is thinking about a ...

  9. ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall

    题目链接:https://nanti.jisuanke.com/t/30991 2000ms 262144K   Feeling hungry, a cute hamster decides to o ...

随机推荐

  1. CODEFORCES掉RATING记 #4

    比赛:Codeforces Round #427 (Div. 2) 时间:2017.7.31晚 开场发现有6道题,都是水题(可能我只会做水题) A:比较\(2t_1+sv_1\)与\(2t_2+sv_ ...

  2. bzoj 3626 : [LNOI2014]LCA (树链剖分+线段树)

    Description 给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1.设dep[i]表示点i的深度,LCA(i,j)表示i与j的最近公共祖先.有q ...

  3. MySQL 练习题 附答案,未完

    综合练习题 表结构 整合一下方便查看 teacher  student  course scors 练习题 1.自行创建测试数据 create table student( sid int prima ...

  4. python学习日记(练习,流程控制+数据结构)

    简易计算器 #简易计算器,蠢新一枚,功能尚不完善,本为个人练习,仅供参考 while 1: a = input('请输入第一个运算数:').strip()#可输入前后带空格的数字 if a.lower ...

  5. LOJ #2142. 「SHOI2017」相逢是问候(欧拉函数 + 线段树)

    题意 给出一个长度为 \(n\) 的序列 \(\{a_i\}\) 以及一个数 \(p\) ,现在有 \(m\) 次操作,每次操作将 \([l, r]\) 区间内的 \(a_i\) 变成 \(c^{a_ ...

  6. Codeforces 700 C. Break Up(Tarjan求桥)

    题意 给你一个有 \(n\) 个点, \(m\) 条边的无向图,每条有边权 \(w_i\) ,现在要选择至多两条边断开,使得 \(S, T\) 不连通,并且使得边权和尽量小. \(n \le 1000 ...

  7. C++类相关

    本文打算通过一些小例子来说明几个关键的知识点. 一:成员函数相关 #include <iostream> using namespace std; class D { public: vo ...

  8. BZOJ3779重组病毒LCT

    题目描述 黑客们通过对已有的病毒反编译,将许多不同的病毒重组,并重新编译出了新型的重组病毒.这种病毒的繁殖和变异能力极强.为了阻止这种病毒传播,某安全机构策划了一次实验,来研究这种病毒.实验在一个封闭 ...

  9. [BJWC2018]Border 的四种求法(后缀自动机+链分治+线段树合并)

    题目描述 给一个小写字母字符串 S ,q 次询问每次给出 l,r ,求 s[l..r] 的 Border . Border: 对于给定的串 s ,最大的 i 使得 s[1..i] = s[|s|-i+ ...

  10. docker镜像操作

    1.获取镜像 docker pull NAME[:TAG] 如果不显式地指定TAG,则默认会选择latest标签,即下载仓库中最新版本的镜像.//获取最新镜像docker pull ubuntu // ...