http://codeforces.com/contest/1072/problem/D

bfs

走1步的最佳状态 -> 走2步的最佳状态 -> ……

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define nl 2.7182818284
const ll mod=1e9+;//
const int maxn=2e3+; struct node
{
int x,y;
}q[maxn*][maxn]; int ci[maxn][maxn],g[maxn*];
char ch[maxn][maxn],s[maxn][maxn],str[maxn*]; int main()
{
int n,maxci,x,y,c,xx,yy,u,v,i,ii,j;
scanf("%d%d",&n,&maxci);
for (i=;i<=n;i++)
scanf("%s",s[i]+);
for (i=;i<=n;i++)
for (j=;j<=n;j++)
ch[i][j]='z'+; g[]=,q[][].x=,q[][].y=;
if (maxci== && s[][]!='a')
{
ci[][]=;
ch[][]=s[][];
}
else
{
ci[][]=maxci-(s[][]!='a');
ch[][]='a';
}
printf("%c",ch[][]); for (i=;i<=n+n-;i++)
{
ii=i-;
for (j=;j<=g[ii];j++)
{
x=q[ii][j].x;
y=q[ii][j].y;
c=ci[x][y];
if (x!=n)
{
xx=x+;
yy=y; if (c== && s[xx][yy]!='a')
{
u=;
v=s[xx][yy];
}
else
{
u=c-(s[xx][yy]!='a');
v='a';
} if (v<ch[xx][yy] || (v==ch[xx][yy] && u>ci[xx][yy]))
ci[xx][yy]=u,ch[xx][yy]=v;
} if (y!=n)
{
xx=x;
yy=y+; if (c== && s[xx][yy]!='a')
{
u=;
v=s[xx][yy];
}
else
{
u=c-(s[xx][yy]!='a');
v='a';
} if (v<ch[xx][yy] || (v==ch[xx][yy] && u>ci[xx][yy]))
ci[xx][yy]=u,ch[xx][yy]=v;
}
} v='z';
for (x=;x<=n;x++)
{
y=i+-x;
if (y>= && y<=n && ch[x][y]!='z'+)
{
if (ch[x][y]<v)
{
v=ch[x][y];
g[i]=;
q[i][].x=x,q[i][].y=y;
}
else if (ch[x][y]==v)
{
g[i]++;
q[i][g[i]].x=x,q[i][g[i]].y=y;
}
}
}
printf("%c",v);
}
return ;
}

Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path的更多相关文章

  1. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  2. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  3. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)D(思维,DP,字符串)

    #include<bits/stdc++.h>using namespace std;char c[2007][2007];char ans[4007];int s[2007][2007] ...

  4. (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

    A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】

    传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...

  6. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】

    任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...

  7. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences(DP)

    题目链接:http://codeforces.com/contest/1058/problem/E 题意:给出 n 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...

  8. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup

    题意:把一长串字符串 排成矩形形式  使得行最小  同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可   每行不能相差大于等于两个字符相当于  ...

  9. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano

    题意:给出一个数列 a1 a2......an  让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i)  那么b( ...

随机推荐

  1. PAT甲级题解-1066. Root of AVL Tree (25)-AVL树模板题

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6803291.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  2. JS进阶系列之执行上下文

    function test(){ console.log(a);//undefined; var a = 1; } test(); 也许你会遇到过上面这样的面试题,你只知道它考的是变量提升,但是具体的 ...

  3. STL next_permutation()

    用法 字典序全排列 可以发现函数next_permutation()是按照字典序产生排列的,并且是从数组中当前的字典序开始依次增大直至到最大字典序. 代码 #include<iostream&g ...

  4. HashMap和HashTable区别【转载】

    今天看到的HashMap和HashTable区别介绍,收藏留着学习. 出处:http://www.importnew.com/24822.html 代码版本 JDK每一版本都在改进.本文讨论的Hash ...

  5. 《Linux内核设计与实现》读书笔记四

    Chapter 3 进程管理 3.1 进程 进程就是处于执行期的程序(目标码存放在某种存储介质上),但进程并不仅仅局限于一段可执行程序代码.通常进程还要包含其他资源,像打开的文件,挂起的信号,内核内部 ...

  6. Java开发异常

    1.org.apache.catalina.LifecycleException 报错信息如下: 警告: Error during context [/wxqhbcloud] restart org. ...

  7. WIFI探针技术

    1.WIFI 探针定义 WIFI 探针是一种能够主动识别 Android 和 IOS 设备,感知用户行为轨迹的精准数据收集前端,基于 WIFI探测技术.移动互联网和云计算等先进技术自动识别探针附近的智 ...

  8. 2017BUAA软工第0次作业

    第一部分:结缘计算机 1. 你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢? 我在上大学之前,其实一直就没怎么考虑过自己以后想要选什么专业,只知道一个大致的方向一定是理工科.毕竟大学之前, ...

  9. 『编程题全队』Beta 阶段用户使用调查报告

    目录 一.项目概述 1.1项目名称 1.2项目简介 1.3项目预期达到目标 1.4项目测试方法 二.项目测试过程 2.1测试对象 2.2测试时长 2.3用户测试反馈 一.项目概述 1.1项目名称 本次 ...

  10. MySQL基础~~增、删、改、简单查

    mysql> desc demo; +-----------+------------+------+-----+---------+----------------+ | Field | Ty ...