【ACM-ICPC 2018 南京赛区网络预赛 E】AC Challenge
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
写个DP
设f[j]表示已经做的题的状态为j的情况下接着选能获得的最大分数。
显然是个倒推。
记忆化搜索一波
dfs(i,j) 表示当前选了i个题,已选状态为j。
(当然这个i可以不用写。因为可以看看j的二进制形式中1的个数来表示i
然后枚举j状态下,下一个要选哪个题。
f[j]的话。就是max({f[nextj]+dep*a[i]+b[i]}当然也可能接下来就不选了。所以f[j] = max(f[j],0);
**注**
这题正着来好像不太好做。
f[j]如果表示为已经做题状态为j的情况下的最大值的话。
f[nextj]不一定只能由f[j]来获得。
感觉就很麻烦吧。。
逆着来的话。
对于f[j]它的所有可能的nextj是固定的。
所以可以直接取max(f[nextj]+转移对应的a[i],b[i]);
且这个nextj有单调性。因为1的个数一直在递增。所以没有后效性。
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 20;
int n;
LL a[N+10],b[N+10];
int statu[N+10];
LL dp[(1<<20)+5];
LL dfs(int dep,int status){
if (dp[status]!=-1) return dp[status];
LL ma = 0;
rep1(i,1,n){
int statu1 = status>>(i-1);
statu1&=1;
if (statu1>0) continue;
statu1 = status&statu[i];
if (statu1!=statu[i]) continue;
statu1 = status|(1<<(i-1));
ma = max(ma,dfs(dep+1,statu1)+1LL*a[i]*dep+b[i]);
}
return dp[status] = ma;
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
scanf("%d",&n);
for (int i = 1;i <= n;i++){
scanf("%lld%lld",&a[i],&b[i]);
int x;
scanf("%d",&x);
rep1(j,1,x){
int y;
scanf("%d",&y);
statu[i]|=(1<<(y-1));
}
}
memset(dp,255,sizeof dp);
printf("%lld\n",dfs(1,0));
return 0;
}
【ACM-ICPC 2018 南京赛区网络预赛 E】AC Challenge的更多相关文章
- ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge(状压dp)
https://nanti.jisuanke.com/t/30994 题意 给你n个题目,对于每个题目,在做这个题目之前,规定了必须先做哪几个题目,第t个做的题目i得分是t×ai+bi问最终的最大得分 ...
- 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& ...
- 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 ...
- ACM-ICPC 2018 南京赛区网络预赛 J.sum
A square-free integer is an integer which is indivisible by any square number except 11. For example ...
- ACM-ICPC 2018 南京赛区网络预赛 E题
ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...
- ACM-ICPC 2018 南京赛区网络预赛B
题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...
- 计蒜客 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 ...
- 计蒜客 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 ...
- 计蒜客 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 ...
- 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 ...
随机推荐
- poj2299--归并排序求逆序数
/** \brief poj2299 * * \param date 2014/8/5 * \param state AC * \return memory 4640K time 3250ms ...
- dlopen failed: empty/missing DT_HASH in "libx.so" (built with --hash-style=gnu?)
崩溃日志内容: java.lang.UnsatisfiedLinkError: dlopen failed: empty/missing DT_HASH in "libxxxx.so&quo ...
- Item 8:析构函数不要抛出异常 Effective C++笔记
Item 8: Prevent exceptions from leaving destructors. 析构函数不要抛出异常 因为析构函数经常被自己主动调用,在析构函数中抛出的异常往往会难以捕获,引 ...
- C语言 - 头文件使用案例
源代码分门别类管理,通过头文件. 放置一些函数声明,变量声明,常量定义,宏定义. hotel.h #ifndef HOTEL_H_INCLUDED #define HOTEL_H_INCLUDED # ...
- [POJ 3345] Bribing FIPA
[题目链接] http://poj.org/problem?id=3345 [算法] 树形背包 [代码] #include <algorithm> #include <bitset& ...
- 关于类和对象的进一步讨论 C++
如果一个类中所有成员函数都是公用的,则可以在定义对象时对数据成员进行初始化: class Time { public: hour; minute; sec; }; Time t1={14,15,23 ...
- php pdo操作
PDO(PHP Data Object) 是PHP 5 中加入的东西,是PHP 5新加入的一个重大功能,因为在PHP 5以前的php4/php3都是一堆的数据库扩展来跟各个数据库的连接和处理,什么 p ...
- mysqls,为node.js而编写的sql语句生成插件 (crud for mysql).
It is written in JavaScript,crud for mysql.You can also use transactions very easily. mysqls 一款专为nod ...
- .NET微服务架构及API网关
一.MSA简介 1.1.MSA是什么 微服务架构MSA是Microservice Architecture的简称,它是一种架构模式,它提倡将单一应用程序划分成一组小的服务,服务之间互相通讯.互相配合, ...
- php 微信支付 回调通知不停的坑
微信支付已完工,最后有点小问题就是微信的回调会重复9次 第一步: $return = "success"; echo $return; 不管用 第二步: $return = &qu ...