GDUT 游戏王(状压DP)
来源:互联网 发布:淘宝网店经营 编辑:程序博客网 时间:2024/05/16 18:56
Description
小学的时候,Stubird非常喜欢玩游戏王,有一天,他发现了一个绝佳的连锁组合,这个连锁组合需要6张卡, 可是他一张都没有,但是他的那些朋友们有,不过当然,他们不会白给,不过也不排除有人和他交情好,送给他了。 不过他们有成全别人的美德,当他们看到Stubird已经有某些他们喜欢的卡的时候,他们会给他优惠,或者更贵也说不定 嘛不过,你可以把有的卡片藏起来,不告诉他们,来获得更低的价格。 问他最少需要多少钱才可以集齐所有的卡。
Input
第一行T,表示有T个测试样例 第二行,n表示他有n个朋友(n<=100) 下一行,m(0<=m<=2的6次方)表示有多少种卡片的集合,num表示他有的这张卡片的编号是(0-5),数据保证所给的集合不重复; 3*m行,第一行都有一个数,k(k<=5),表示这个集合包含的卡片张数 下一行k个数,表示每张卡片的编号(0-5)(不会包含num) 下一行一个数c,表示如果你有这个组合下购买num卡,所需要的花费c;
Output
输出最小的花费,如果不可能集齐则输出-1
Sample Input
161 00 11 10 11 20 11 30 11 40 11 50 1
Sample Output
6
题比较难懂,但也是一个基本的状压DP。
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<bitset>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair<int,int>pil;const int INF=0x3f3f3f3f;int dp[(1<<7)+100];int cost[5100],num[5100];int stau[5100];int t,n,m,id;int main(){ int x; scanf("%d",&t); while(t--) { scanf("%d",&n); int cnt=0,k;CLEAR(stau,0); for(int i=1;i<=n;i++) { scanf("%d%d",&m,&id); for(int j=1;j<=m;j++) { num[cnt]=id; scanf("%d",&k); while(k--) { scanf("%d",&x); stau[cnt]|=(1<<x); } scanf("%d",&cost[cnt]); cnt++; } } CLEAR(dp,INF); dp[0]=0;int status=(1<<6)-1; for(int i=0;i<=status;i++) { if(dp[i]==INF) continue; for(int j=0;j<cnt;j++) { if(i&(1<<num[j])) continue; if((i|stau[j])!=i) continue; int st=i^(1<<num[j]); dp[st]=min(dp[st],dp[i]+cost[j]); } } int ans; if(dp[status]==INF) ans=-1; else ans=dp[status]; printf("%d\n",ans); } return 0;}
0 0
- GDUT 游戏王(状压DP)
- GDUT决赛 游戏王
- gdut
- GDUT决赛 - Problem H: 悦动达人(DP)
- DP——GDUT #E 绕远路
- GDUT决赛 - Problem B: 完美串(DP`LCS)
- [GDUT]1060: 跟XxX_Stu 玩游戏(很简单题目)
- GDUT 2016新生赛D题 有趣的游戏
- 【状压DP】棋盘游戏 board
- 2015广东工业大学ACM校赛 I 游戏王 (状压dp)
- 2016Y GDUT新生杯初赛 Problem D: 有趣的游戏
- [GDUT-ACM]
- 洛谷 P1278 单词游戏 【状压dp】
- 【区间DP】乘法游戏
- 传球游戏(DP)
- voj1485 传球游戏 dp
- 数字游戏 (dp)
- FZU2126:消去游戏(DP)
- JAVA设计模式(二十)——备忘录模式
- Linux启动过程概述(X86)
- 实现UML 序列图 -- csdn MarkDown 第六篇 技术篇
- Java synchronized 用法
- 程序员练级攻略(CoolShell)
- GDUT 游戏王(状压DP)
- horizon is easy and complex
- UEditor
- OSI七层模型详解
- maven
- POJ 3744 Scout YYF I (概率dp+矩阵优化)
- Linux显示一行显示列总计
- 使用webView显示网页
- android开发之消息推送