题意:一个特殊21点游戏 具体http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2852

题解:建一个三维dp,表示三个卡槽分别为i,j,l分时最大的收益情况。

    对所有当前状态dp,将下一个可能的状态存入f,

坑:~-1==0

#define _CRT_SECURE_NO_WARNINGS
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<string>
#include<stack>
#include<ctime>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<fstream>
#include<iostream>
#include<functional>
#include<algorithm>
#include<memory.h>
//#define INF 0x3f3f3f3f
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
#define mmm(a,b) memset(a,b,sizeof(a))
//std::ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void smain();
#define ONLINE_JUDGE
int main() {
//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
FILE *myfile;
myfile =freopen("C:\\Users\\SuuTT\\Desktop\\test\\in.txt", "r", stdin);
if (myfile == NULL)
fprintf(stdout, "error on input freopen\n");
/*FILE *outfile;
outfile= freopen("C:\\Users\\SuuTT\\Desktop\\test\\out.txt", "w", stdout);
if (outfile == NULL)
fprintf(stdout, "error on output freopen\n");*/
long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
int dir[][] = { ,,,,-,,,- };
const int maxn = 2e2 + ;
int f[][][], dp[][][]; int n; int ans;
int num(char c) {
if (c >= ''&&c <= '')return c - '';
else if (c == 'A')return ;
else if (c == 'F')return -;
else return ;
} void smain() {
while (cin >> n) {
if (n == )break;
mmm(f, ); mmm(dp, );
string c;
cin >> c;
int x = num(c[]);
if (x==-) {
//cout << ~x << endl;
dp[][][] = ;
ans = ;
}
else {
dp[x][][] = ;
dp[][x][] = ;
dp[][][x] = ;
ans = ;
}
rep(i, , n) {
string c;
cin >> c;
int x = num(c[]);
rep(j, , )rep(k, , )rep(l, , ) if(dp[j][k][l]){
int t = dp[j][k][l];
if ((x == - && j < ) || x + j == ) f[][k][l] = max(f[][k][l], t + );//放第一组//正好21,[j][k][l]->[0][k][l]
else if (x + j < )f[j + x][k][l] = max(f[x + j][k][l], t + );//没到21[j][k][l]->[x + j][k][l]
else if (x + j > && j < )f[][k][l] = max(f[][k][l], t + );//超了21[j][k][l]->[21][k][l] if ((x == - && k < ) || x + k == ) { f[j][][l] = max(f[j][][l], t + ); }
else if (x + k < )f[j][k+x][l] = max(f[j][k+x][l], t + );
else if (x + k > && k < )f[j][][l] = max(f[j][][l], t + ); if ((x == - && l < ) || x + l == ) { f[j][k][] = max(f[j][k][], t + ); }
else if (x + l < )f[j][k][l+x] = max(f[j][k][l+x], t + );
else if (x + l > && l < )f[j][k][] = max(f[j][k][], t + );
}
rep(j, , )rep(k, , )rep(l, , )dp[j][k][l] = f[j][k][l], ans = max(ans,dp[j][k][l]), f[j][k][l] = ;
}
cout << ans << endl;
} }

Deck of Cards ZOJ - 2852 dp 多决策 三维 滚动更新的更多相关文章

  1. Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)

    Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...

  2. Codeforces 745E Hongcow Buys a Deck of Cards 状压DP / 模拟退火

    题意:现在有n张卡片(n <= 16), 每一轮你可以执行两种操作中的一种.1:获得一张红色令牌和一张蓝色令牌.2:购买一张卡片(如果可以买的话),购买的时候蓝色卡片可以充当蓝色令牌,红色同理, ...

  3. codeforces 744C Hongcow Buys a Deck of Cards

    C. Hongcow Buys a Deck of Cards time limit per test 2 seconds memory limit per test 256 megabytes in ...

  4. Codeforces Round #385 (Div. 1) C. Hongcow Buys a Deck of Cards

    地址:http://codeforces.com/problemset/problem/744/C 题目: C. Hongcow Buys a Deck of Cards time limit per ...

  5. [Swift]LeetCode914.一副牌中的X | X of a Kind in a Deck of Cards

    In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...

  6. X of a Kind in a Deck of Cards LT914

    In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...

  7. LeetCode - X of a Kind in a Deck of Cards

    In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...

  8. POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)

    POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...

  9. 914. X of a Kind in a Deck of Cards

    In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...

随机推荐

  1. 在Asp.Net MVC中使用Repeater控件

    使用Repeater控件在视图中展示图表信息,Repeater控件的使用概述: <asp:Repeater ID="Repeater1" runat="server ...

  2. Effective Java 第三版——61. 基本类型优于装箱的基本类型

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  3. s:if 标签 字符串比较 正确用法和错误用法

    transaction.tjpopState 该对象在后台是枚举类型,在前台需要转为字符串才能比较. 错误一: <s:if test='transaction.tjpopState!=" ...

  4. ansible执行shell模块和command模块报错| FAILED | rc=127 >> /bin/sh: lsof: command not found和| rc=2 >> [Errno 2] No such file or directory

    命令: ansible -i hosts_20 st  -m shell -a 'service zabbix_agentd star'  -K --become ansible -i hosts_2 ...

  5. BW中DSO的分类及应用

    1.DSO的分类,标准DSO(生成主数据标识.对于相同关键字段的值进行合并.可直接出具报表).写优化的DSO(不生成主数据标识.不合并相同关键字段的值.速度快可用于存储大容量数据).直接写入的DSO, ...

  6. golang:吐槽multipart的设计

    最近在做邮件解析的工作,因此接触到multipart库,用了之后才发现golang的multipart有一点设计很诡异. 红线标出来的话意思是:当Content-Transfer-Encoding的值 ...

  7. mysql解决大量time_wait

    mysql解决大量time_wait     命令查看TIME_WAIT连接数 netstat -ae|grep "TIME_WAIT" |wc -l 早上登陆服务器的时候输入ne ...

  8. Java知多少(101)图像缓冲技术

    当图像信息量较大,采用以上直接显示的方法,可能前面一部分显示后,显示后面一部分时,由于后面一部分还未从文件读出,使显示呈斑驳现象.为了提高显示效果,许多应用程序都采用图像缓冲技术,即先把图像完整装入内 ...

  9. myeclipse创建hibernate工程

    1.创建数据库: from blog http://www.cnblogs.com/zhaocundang/p/9061959.html 使用navicat mysql IDE: 创建数据库 book ...

  10. alibaba的FastJson(高性能JSON开发包) json转换

    http://www.oschina.net/code/snippet_228315_35122 class User{ private int id; private String name; pu ...