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

这题挺好的 看题解看了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. Lightmapping

    当游戏场景包含了大量的多边形时,实时光源和阴影对游戏性能的影响会很大.这时更适合使用Lightmapping技术,将光线效果预渲染成贴图使用到多边形上模拟光影效果.这种方式不用担心光源数量和阴影对性能 ...

  2. python num[y array

    http://sebug.net/paper/books/scipydoc/numpy_intro.html npArr1=np.array([1,2,3],[4,5,6],[7,8,9]]) npA ...

  3. linux作业六——进程的描述和进程的创建

    进程的描述和进程的创建 一.进程描述符task_struct 为了管理进程,内核必须对每个进程进行清晰的描述,进程描述符提供了内核所需了解的进程信息. 代码关键点: 1.Struct list_hea ...

  4. 从地址栏输入url到显示页面都发生了什么?

    作为一个软件开发者,你一定会对网络应用如何工作有一个完整的层次化的认知,同样这里也包括这些应用所用到的技术:像浏览器,HTTP,HTML,网络服务器,需求处理等等. 本文将更深入的研究当你输入一个网址 ...

  5. HTTP - 内容编码

    HTTP 应用程序有时在发送之前需要对内容进行编码.例如,在把很大的 HTML 文档发送给通过慢速连接上来的客户端之前,服务器可能就会对它进行压缩,这样有助于减少传输实体的时间. 内容编码过程 内容编 ...

  6. c# XAML

    http://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/hh465340.aspx 如果你选择在 Microsoft Visual Basi ...

  7. What is the difference between Views and Materialized Views in Oracle?

    aterialized views are disk based and update periodically base upon the query definition. Views are v ...

  8. crontab 指定执行用户

    linux下可以通过配置crontab来定时执行任务,执行体可以是一条系统命令或自己写的一个脚本,同时可以指派用户来执行.配置crontab有两种方法.方法1.使用crontab命令,例如添加一个新的 ...

  9. Java Socket 使用BufferedWriter和BufferedReader要注意readLine 以及换行标志的发送

    当接收的类使用的是BufferedReader,发送的类是BufferedWriter的时候,要注意发送的一行要有换行标识符. 请看下面一个例子,服务器接收不到客户端的信息. 服务器: import ...

  10. 为什么Android 3.0如此罕见?

    3.0(2011年2月)代号蜂巢,专用于android系统的平板电脑,不用于手机.4.0(2011年5月公布)的开发就是让平板电脑和手机能够共用一个版本的系统.4.0通用于平板电脑和手机.