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. 【XSY2524】唯一神 状压DP 矩阵快速幂 FFT

    题目大意 给你一个网格,每个格子有概率是\(1\)或是\(0\).告诉你每个点是\(0\)的概率,求\(1\)的连通块个数\(\bmod d=0\)的概率. 最开始所有格子的概率相等.有\(q\)次修 ...

  2. [SPOJ913]QTREE2 - Query on a tree II【倍增LCA】

    题目描述 [传送门] 题目大意 给一棵树,有两种操作: 求(u,v)路径的距离. 求以u为起点,v为终点的第k的节点. 分析 比较简单的倍增LCA模板题. 首先对于第一问,我们只需要预处理出根节点到各 ...

  3. POJ2411 铺地砖 Mondriaan's Dream

    Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 15962   Accepted: 923 ...

  4. iptables(2)

    MASQUERADE同样是做源地址转换,只不过防火墙会根据该策略自动查找可用的公网IP地址,适应变化的情况•若接口使用ppp+,表示匹配ppp0.ppp1……中任意可用的拨号连接•若需要演示操作,可以 ...

  5. 题解 P4512 【【模板】多项式除法】

    题目地址 前言 原理有大佬写了 所以蒟蒻只讲下本题的代码细节 我看懂的大佬博客:博客地址 因为可能知道了大致的步骤还有很多细的地方不理解导致写的时候要花很久并且看到大佬们好像都是用递归写的希望能有帮助 ...

  6. mysql慢查询,死锁解决方案

    1. 先使用root用户登录到MySQL中 2. 使用show processlist查看其查询速率 +----+------+-----------------+------+---------+- ...

  7. js获取元素位置和style的兼容性写法

    今天说一下js获取元素位置和style的方法.当然不只是element.style那么简单.. 主角:getBoundingClientRect,getClientRects,getComputedS ...

  8. HEOI2013 Segment

    传说中的“李超树”. 大意:给你若干线段,试求横坐标x上的最上方一条线段的编号.无则输出零. 解:用线段树维护. 插入的时候保存自己这个区间上可能成为最大值的线段,被抛弃的则看情况下放. 查询时从最底 ...

  9. python描述器

    描述器定义 python中,一个类实现了__get__,__set__,__delete__,三个方法中的任何一个方法就是描述器,仅实现__get__方法就是非数据描述器,同时实现__get__,__ ...

  10. ImageMagick - MAGICK_CODER_MODULE_PATH 测试结果, 很受伤

    //通过查看 ImageMagick 源代码: http://code.metager.de/source/xref/ImageMagick/MagickCore/module.c#552 //首先会 ...