Deck of Cards ZOJ - 2852 dp 多决策 三维 滚动更新
题意:一个特殊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 多决策 三维 滚动更新的更多相关文章
- Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)
Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...
- Codeforces 745E Hongcow Buys a Deck of Cards 状压DP / 模拟退火
题意:现在有n张卡片(n <= 16), 每一轮你可以执行两种操作中的一种.1:获得一张红色令牌和一张蓝色令牌.2:购买一张卡片(如果可以买的话),购买的时候蓝色卡片可以充当蓝色令牌,红色同理, ...
- 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 ...
- 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 ...
- [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 ...
- 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 ...
- 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 ...
- 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 / ...
- 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 ...
随机推荐
- 安装SQL Server For Linux(Install SQL Server)
SQL Server on Ubuntu——Ubuntu上的SQL Server(全截图) 1. 安装SQL Server 官网安装指南:https://docs.microsoft.com ...
- 深入分析java线程池的实现原理(转载)
前言 线程是稀缺资源,如果被无限制的创建,不仅会消耗系统资源,还会降低系统的稳定性,合理的使用线程池对线程进行统一分配.调优和监控,有以下好处: 1.降低资源消耗: 2.提高响应速度: 3.提高线程的 ...
- Background Media Recovery terminated with ORA-1274 after adding a Datafile (Doc ID 739618.1)
APPLIES TO: Oracle Database - Enterprise Edition - Version 9.2.0.1 to 12.1.0.2 [Release 9.2 to 12.1] ...
- IDEA环境设置
设置SDK:https://blog.csdn.net/y999666/article/details/51893348 打开模板使用说明,找到Maven本地安装目录, 备份E:\Program Fi ...
- TitleBar 的那些设置
设置状态栏透明: View decorView = activity.getWindow().getDecorView(); int option = View.SYSTEM_UI_FLAG_LAYO ...
- 第一部分:开发前的准备-第三章 Application 基本原理
第3章 应用程序基本原理 首先我们需要强调一下Android 应用程序是用java写的.Android SDK工具编译代码并把资源文件和数据打包成一个文件.这个名字的扩展名是.APK.要在androi ...
- (转)Linux服务器磁盘空间占满问题
转自:https://www.cnblogs.com/cindy-cindy/p/6796684.html 下面我们一起来看一篇关于Linux服务器磁盘占满问题解决(/dev/sda3 满了),希望碰 ...
- Oracle Enterprise Linux 6.4 下挂载ISCSI 设备
Oracle Enterprise Linux 6.4 下挂载ISCSI 设备一.发现① 要求安装iscsi客户端软件 yum install iscsi-initiator-utils ② 发现 ...
- ABBYY FineReader 12如何识别包含非常规符号的文本
ABBYY FineReader 12 是一款OCR图文识别软件,可快速方便地将扫描纸质文档.PDF文件和数码相机的图像转换成可编辑.可搜索的文本,有时文本中可能会包含一些非常规的符号,此时ABBYY ...
- oracle 数据库对于多列求最大值
1.案例: SELECT GREATEST('36', '55', '34') V_MAX, LEAST('36', '55', '34') V_MIN FROM DUAL Oracle比较一列的最大 ...