2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem H. Password Service dp
Problem H. Password Service
题目连接:
http://www.codeforces.com/gym/100253
Description
Startups are here, startups are there. Startups are everywhere! Polycarp would like to have his own
startup, too. His business idea is a password service. Have you noticed how many hours you spent trying
to create a password?
Polycarp's service will help clients to create a password by requirements. He is thinking about a freemium
business model of monetization. He doesn't know what it is, but he likes the word freemium.
The rst release of Polycarp's startup should have a simple form with two elds. The rst eld is for n,
where n denotes that the required password can consist of only rst n lowercase letters from the Latin
alphabet. The second form eld is for string s containing the characters <',
>' and `='. The sign in position
i denotes the comparison result of the i-th and the (i + 1)-th character in the password. So if the length
of s is l then the required password should consist of exactly l + 1 lowercase letters.
Polycarp oers you a great position in his startup, he oers you to become the CTO. Polycarp can't oer
you a great salary (just only $1), but he will give you so many stock options that in case of IPO exit
you will be a millionaire! Why not? So your task is to write a program to generate a password containing
some of the rst n lowercase letters of the Latin alphabet and which has s as a result of comparisons of
consecutive characters
Input
The rst line of the input contains an integer number n (1 ≤ n ≤ 26), where n denotes that the required
password should contain only lowercase letters from the rst n letters of the Latin alphabet. The second
line contains the string s (the length of s is between 1 and 5000, inclusive), where s consists of the
characters <',
>' and `='. The i-th character stands for the result of comparison of the i-th and the
(i + 1)-th characters of the password.
Output
Print the required password or -1 if it doesn't exist. You may print any answer in case of multiple answers.
Sample Input
5
=<>
Sample Output
bbdc
Hint
题意
给你一个字符串,你可以用n个字符。
要求满足字符串所给的大小关系表示。
题解:
dp,dp[i][j]表示第i个位置用第j个字符可不可行。
然后转移就行了。
其实贪心好像也可以,懒得去想了……
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5005;
char s[maxn];
int p[maxn][26];
pair<int,int> re[maxn][26];
int N,n;
vector<int>ans;
void dfs(int x,int y,int rx,int ry)
{
if(p[x][y])return;
p[x][y]=1;
re[x][y]=make_pair(rx,ry);
if(x==n)return;
if(s[x+1]=='=')
dfs(x+1,y,x,y);
if(s[x+1]=='<')
{
for(int j=y+1;j<N;j++)
dfs(x+1,j,x,y);
}
if(s[x+1]=='>')
{
for(int j=y-1;j>=0;j--)
dfs(x+1,j,x,y);
}
}
int flag = 0;
void dfs2(int x,int y)
{
if(flag)return;
if(re[x][y].first==-1)
{
flag = 1;
reverse(ans.begin(),ans.end());
for(int i=0;i<ans.size();i++)
{
printf("%c",ans[i]+'a');
}
printf("\n");
return;
}
ans.push_back(re[x][y].second);
dfs2(re[x][y].first,re[x][y].second);
}
int main(){
scanf("%d",&N);
scanf("%s",s+1);
n = strlen(s+1);
for(int i=0;i<N;i++)
dfs(0,i,-1,-1);
for(int i=0;i<N;i++)
{
if(p[n][i])
{
ans.push_back(i);
dfs2(n,i);
ans.pop_back();
return 0;
}
}
if(!flag)printf("-1");
}
2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem H. Password Service dp的更多相关文章
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution
A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...
- 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...
随机推荐
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
- CSS function--(来自网易)
/* function */ .f-cb:after,.f-cbli li:after{;overflow:hidden;content:".";} .f-cb,.f-cbli l ...
- 20155238 2016-2017-2 《Java程序设计》第五周学习总结
教材学习内容总结 Java语言中所有的错误都会包装为对象.使用try.catch可以对对象做处理. 设计错误对象都继承自java.lang.Throwable类.Throwable定义了取得错误信息, ...
- JQuery 对表格的详细操作
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding=& ...
- MySQL忘记密码了怎么办?
接手一个项目时,如果上一位负责人没有把项目文档.账号密码整理好是一件很头疼的事情.. 例如,当你想打开MySQL数据库的时候 输入: mysql -u root -p 一回车想输入密码,发现密码错误! ...
- Zookeeper笔记之使用zk实现集群选主
一.需求 在主从结构的集群中,我们假设硬件机器是很脆弱的,随时可能会宕机,当master挂掉之后需要从slave中选出一个节点作为新的master,使用zookeeper可以很简单的实现集群选主功能. ...
- LeetCode(21):合并两个有序链表
Easy! 题目描述: 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4 输出:1- ...
- LeetCode(18):四数之和
Medium! 题目描述: 给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 t ...
- Linux下配置MySQL需要注意的几点
1.为mysql加上连接数,linux下最大能允许8000个mysql连接. 经验下,设置为3000 [mysqld] max_connections=3000
- 解决Only a type can be imported. * resolves to a package
HTTP Status 500 - Unable to compile class for JSP: type Exception report message Unable to compile c ...