这题刚开始理解错题意了 以为只能往右和下走

这题挺好的 看题解看了N久啊

二维的DP 第一维表示走到第几步 可以画一个正方形 以左上角斜着划线 第i步走的点只能是第i条线上的点 而dp的第二维 就表示的第i步可以到达的点的状态

另开一个a数组来表示 第i条线上每个字母的状态

dp所代表的值就为a与b的差值 以这个来进行选择 进行记忆化

确定下一步可以到达的字母的状态 是以当前可达的状态&下一步所要到达的字母的状态

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
using namespace std;
#define LL __int64
#define INF 1e9
int dp[][<<],a[][];
char s[][];
int n;
int dfs(int step,int sta)
{
int i,num=;
if(dp[step][sta]!=INF)
return dp[step][sta];
for(i = ; i < n ; i++)
{
if(sta&(<<i))
{
if(s[step-i][i]=='a') num++;
else if(s[step-i][i]=='b') num--;
break;
}
}
if(step==*n-)
return dp[step][sta] = num;
if(step%!=)
{
dp[step][sta] = -INF;
for(i = ; i < ; i++)
{
int next = a[step+][i]&(sta|(sta<<));
if(next==)
continue;
dp[step][sta] = max(dp[step][sta],dfs(step+,next)+num);
}
return dp[step][sta];
}
else
{
for(i = ; i < ; i++)
{
int next = a[step+][i]&(sta|(sta<<));
if(next==)
continue;
dp[step][sta] = min(dp[step][sta],dfs(step+,next)+num);
}
return dp[step][sta];
}
}
int main()
{
int i,j;
scanf("%d",&n);
for(i = ; i < n ; i++)
cin>>s[i];
for(i = ; i < *n- ; i++)
{
for(j = ; j < n ; j++)
{
if(i-j<||i-j>=n) continue;
a[i][s[i-j][j]-'a'] |= (<<j);
}
}
for(i = ; i < *n ; i++)
for(j = ; j < (<<n) ; j++)
dp[i][j] = INF;
int ans = dfs(,);
if(ans>)
puts("FIRST");
else if(ans<)
puts("SECOND");
else
puts("DRAW");
return ;
}

Codeforces Round #206 (Div. 1)B(记忆化)的更多相关文章

  1. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  2. Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索

    E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...

  3. Codeforces Round #206 (Div. 2) 部分题解

    传送门:http://codeforces.com/contest/355 A:水题,特判0 int k,d; int main(){ //FIN; while(cin>>k>> ...

  4. Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    #include <iostream> using namespace std; int main(){ int k,d; cin >> k >>d; ) { k ...

  5. Codeforces Round #206 (Div. 2)

    只会做三个题: A:简单题,不解释: #include<cstdio> using namespace std; int k,d; int main() { scanf("%d% ...

  6. Codeforces Round #450 (Div. 2)

    Codeforces Round #450 (Div. 2) http://codeforces.com/contest/900 A #include<bits/stdc++.h> usi ...

  7. Codeforces Round #261 (Div. 2)[ABCDE]

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  8. 刷题记录:Codeforces Round #719 (Div. 3)

    Codeforces Round #719 (Div. 3) 20210703.网址:https://codeforces.com/contest/1520. 没错,我是个做div3的蒟蒻-- A 大 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. VB数据库经典实例总结(二)

    大家先看一张似图非图的图. 我们先称它为“过程”也许有不对的地方,在我学数据库到这个阶段.到这个刚刚接触.初生牛犊不怕虎的阶段对它的理解是这样的.所有的都是这个过程.只是在这中间掺杂了一些知识点(我们 ...

  2. ubuntu14.04 安装matlab r2013a

    神奇的linux. 进入主题:matlab相信是不少工程人员缺少不了的工具,就我所在的通信行业更是如此,matlab的linux版本是和windows版本同步更新, 不过r2012之后只提供64位版本 ...

  3. Converting Storyboard from iPhone to iPad

    I found out a kind of solution: Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.s ...

  4. 编译时和运行时、OC中对象的动态编译机制

    编译时 编译时顾名思义就是正在编译的时候.那啥叫编译呢?就是编译器帮你把源代码翻译成机器能识别的代码.(当然只是一般意义上这么说,实际上可能只是翻译成某个中间状态的语言.比如Java只有JVM识别的字 ...

  5. 【转】edittext设置点击链接

    I put some ClickableSpan in EditText, unfortunately, that spans are still not clickable. When I clic ...

  6. win8安装新字体

    http://jingyan.baidu.com/article/e3c78d640a7ab33c4c85f52d.html

  7. Apache Spark探秘:三种分布式部署方式比较

    转自:链接地址: http://dongxicheng.org/framework-on-yarn/apache-spark-comparing-three-deploying-ways/     目 ...

  8. OD鲜为人知的小技巧--搜索通配符(关键字)

    我看过一些OD教程,关于通配符这一点很少有人讲解(大概是我看的教程少吧)  近日通过看<黑客反汇编揭秘(第二版)>第165页了解到,原来OD还有这样方便的功能,那就是搜索通配符: Olly ...

  9. [设计模式] 1/2 工程与抽象工程模式 factory & Abstrac Factory

    转载 http://blog.csdn.net/wuzhekai1985 软件领域中的设计模式为开发人员提供了一种使用专家设计经验的有效途径.设计模式中运用了面向对象编程语言的重要特性:封装.继承.多 ...

  10. Java学习第二篇:类,对象,成员属性,成员方法,构造方法,类变量,类方法

    一.类的定义 一个全面的类定义是比较复杂的,  定义如下: