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];
int main(){
memset(s,-1,sizeof(s));
int n,k;
scanf("%d%d",&n,&k);
getchar();
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%c",&c[i][j]);
}
getchar();
}
s[1][1]=k;//初始可改变的次数
char mn=0;
char tmp=0;
for(int i=1;i<=n*2-1;i++){
mn='z';
for(int j=1;j<=i;j++){
if(j>n||i-j+1>n)
continue;
if(s[j][i-j+1]>-1){//可达位置
tmp=c[j][i-j+1];
if(tmp!='a'&&s[j][i-j+1]>0)//改变机会未用完
tmp='a';
mn=min(mn,tmp);
}
}
ans[i]=mn;//i可走到的位置的最小值
for(int j=1;j<=i;j++){
if(j>n||i-j+1>n)
continue;
if(s[j][i-j+1]>-1){
tmp=c[j][i-j+1];
if(tmp!='a'&&s[j][i-j+1]>0){//贪心,前面有机会能变a就变
tmp='a';
s[j][i-j+1]--;
}
if(tmp==mn){//可行出路之一
if(j<n)
s[j+1][i-j+1]=max(s[j+1][i-j+1],s[j][i-j+1]);//走改变少的路
if(i-j+1<n)
s[j][i-j+2]=max(s[j][i-j+2],s[j][i-j+1]);//走改变少的路
}
}
}
printf("%c",ans[i]);
}
return 0;
}
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)D(思维,DP,字符串)的更多相关文章
- 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++ ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path
http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...
- 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 ...
- (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 ...
- 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 ...
- 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 ...
- 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 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup
题意:把一长串字符串 排成矩形形式 使得行最小 同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可 每行不能相差大于等于两个字符相当于 ...
- 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( ...
随机推荐
- CSS3分享功能
[代码][CSS]代码 $.fn.share = function(opts) { var $body, $head; if ($(this).length === 0) { consol ...
- zTree获取(子)节点
var ids=[]; ids=getChildren(ids, treeNode);//TreeNode是选中节点,ids是子节点id数组,格式:123,223,4,55 1.获取直接子节点的id ...
- Prototype Chain
参考资料: <javascript权威指南 第六版> <javascript高级程序设计 第二版> 写在前面的话 所谓的原型链就是一个一个的对象通过其__proto__属性连接 ...
- HIVE SQL JOIN
最近总结了一下hive表关联的用法,与Postgres表关联还是有细微差别,总结在这里方便以后查看. join语法 join_table: table_reference [INNER] JOIN t ...
- stl_multimap.h
stl_multimap.h // Filename: stl_multimap.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: ...
- Struts2 - 异常处理: exception-mapping 元素
异常处理: exception-mapping 元素 在action方法中添加 int i=1/0; 请求action后,结果为: 在struts.xml中添加异常处理:exception-mappi ...
- 跨平台的WebRTC客户端框架:OpenWebRTC
Webrtc的ios框架编译 http://www.th7.cn/Program/IOS/201502/390418.shtml WebRTC in WebKit : http://www.webrt ...
- 无旋Treap - BZOJ1014火星人 & 可持久化版文艺平衡树
!前置技能&概念! 二叉搜索树 一棵二叉树,对于任意子树,满足左子树中的任意节点对应元素小于根的对应元素,右子树中的任意节点对应元素大于根对应元素.换言之,就是满足中序遍历为依次访问节点对应元 ...
- CodeForces - 1C:Ancient Berland Circus (几何)
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things ...
- UVA11059 - Maximum Product
1.题目名称 Maximum Product 2.题目地址 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemi ...