题意:一个特殊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. 【Windows】查看Windows上运行程序的异常日志

    任何在windows系统上运行的程序,只要发生异常导致程序异常终止,windows都会在日志中详细记录这个异常.可以在计算机管理中查看,如图:也可以在操作中心查看,如图:

  2. Sql Server 阻塞的常见原因和解决办法

    1. 由于语句运行时间太长而导致的阻塞,语句本身在正常运行中,只须等待某些系统资源 解决办法: a. 语句本身有没有可优化的空间 b. Sql Server 整体性能如何,是不是有资源瓶颈影响了语句执 ...

  3. 搞定所有的跨域请求问题 jsonp CORS

    网上各种跨域教程,各种实践,各种问答,除了简单的 jsonp 以外,很多说 CORS 的都是行不通的,老是缺那么一两个关键的配置.本文只想解决问题,所有的代码经过亲自实践.   本文解决跨域中的 ge ...

  4. eoe移动开发者大会—移动开发者的极客盛宴 2013年9月14日期待您的加入!!

    2013 eoe移动开发者大会北京站即将盛大开启!      大会介绍 由国内最大的移动开发者社区eoe主办,在行业盟友的倾力支持下,集合了来自微软.Google.亚马逊.ARM等跨国公司业务负责人的 ...

  5. 对于移动端 App,虚拟机注册或类似作弊行为有何应对良策?

    1.APP攻击大致策略 对APP进行攻击的一般思路包括反编译APP代码.破解APP通讯协议.安装虚拟机自动化模拟: a.首先看能否反编译APP代码(例如Android APP),如果能够反编译,从代码 ...

  6. 【系统移植】uboot详细分析

    uboot使用 uboot控制台,倒计时    命令: 调试,操作一些硬件 setenv printenv saveenv  nand erase  nand write  tftp zImage h ...

  7. Thrift 源码学习一——源码结构

    Thrift 客户端与服务端的交互图 源码结构 传输层 TTransport: TTransport:客户端传输层抽象基础类,read.write.flush.close 等方法 TSocket 与 ...

  8. Java连接各种数据库写法

    # 示例配置参考,涵盖几乎所有的主流数据库 ############# Oracle数据库 ######################## #   数据库驱动名 driver=oracle.jdbc ...

  9. idea配置项目运行时内存大小

    选择 edit Configurations : -server -XX:PermSize=1024M -XX:MaxPermSize=2048M

  10. 教你一招:解决Windows 开机弹出AotuIt ERROR 错误

    AutoIt是个脚本语言,常被用于自动化安装.网络上有些系统镜像里含有AutoIt脚本,用于系统的自动配置.出现这种问题往往有两种可能的原因: 1)做系统的时候没搞好.这种情况就需要换一个镜像文件. ...