题意:一个特殊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. 转 $(document).ready()与window.onload的区别

    $(document).ready()和window.onload在表单上看都是页面加载时我们就去执行一个函数或动作,但是在具体的细节上$(document).ready()和window.onloa ...

  2. 用VS2012建立core2.1网站项目后引用Microsoft.AspNetCore.Session不了

    做个.NET CORE的新项目,和往常一样,VS2017新建CORE项目(CORE2.1),NUGET引入session,结果引入不了,说什么版本不对应的,把SESSION降了一个版本,可以安装上了, ...

  3. Git应用实践(一)

    [时间:2017-03] [状态:Open] [关键词:Git,ssh,远程仓库,git remote] 0-背景 近期在使用Git@oschina上发现以下两个问题: 我的提交有两个名和email, ...

  4. 9款最好的JavaScript压缩工具

    削减是一个从源代码中删除不必要的字符的技术使它看起来简单而整洁.这种技术也被称为代码压缩和最小化.在这里,我们为你收集了10个最好的JavaScript压缩工具将帮助您删除不必要的空格,换行符,评论, ...

  5. LeetCode: Subsets 解题报告

    Subsets Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset ...

  6. Android 自动化测试——Monkey测试

    Android自带了很多方便的测试工具和方法,包括我们常用的单元测试.Robotium测试.Monkey测试.MonkeyRunner测试.senevent模拟等.这些方法对于我们编写高质量的APP十 ...

  7. github新建repositories后import已有code 随后同步更新

    github上,可以forks别人已有的项目,而且同步更新合并也很方便,但如果是自己新建的项目,而导入的是别人的代码修改后,别人的又更新了,自己想获取他的更新,怎么办呢?其实很简单. # git cl ...

  8. c++ 出现“ error LNK2019: 无法解析的外部符号 该符号在函数 中被引用"错误原因

    一般问题出在 (1)XXX.lib头文件,这个要包含(不然编译也不能通过) (2)需要XXX.lib或XXX.dll库.手动添加,项目->属性->配置属性->链接器->输入 然 ...

  9. 使用echo $? 查看命令是否执行成功

    shell中的特殊变量:变量名含义$0shell或shell脚本的名字$*以一对双引号给出参数列表$@将各个参数分别加双引号返回$#参数的个数$_代表上一个命令的最后一个参数$$代表所在命令的PID$ ...

  10. Spring Java-based容器配置

    多年以来,Spring大量的XML配置及复杂的依赖管理饱受非议. 为了实现免XML的开发体验.Spring加入了新的配置注解以支持Java Config开发模式,当中最重要的注解就是@Configur ...