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的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 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 ...

  4. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  5. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  6. 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, ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 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$ 思路: 定义一个二元组$< ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. 51Nod 1684 子集价值 (平方和去括号技巧)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1684 题意: 新建一个位运算,求所有子集通过这个位运算后的答案的平方和是 ...

  2. 第12月第14天 sfml cmake

    1. cd Desktop/mycode/ ls mkdir sfml03 cd sfml03 ls vi main.cpp vi config.h vi CMakeLists.txt ls pwd ...

  3. Markdown基础教程

    标题 Markdown支持6种级别的标题,对应html标签 h1 ~ h6

  4. Dream------Hbase--0.94版本和0.98/1.X版本api变动

    Dream------Hbase--0.94版本和0.98/1.X版本api变动 网上好多说getQualifier.getValue.getRow被..Array代替了,其实并不是的. 1. Int ...

  5. Web安全测试-WebScarab

    [功能] WebScarab是一个用来分析使用HTTP和HTTPS协议的应用程序框架.其原理很简单,WebScarab可以记录它检测到的会话内容(请求和应答),并允许使用者可以通过多种形式来查看记录. ...

  6. CentOS下配置MySQL允许root用户远程登录

    1.常用命令: 安装上传下载文件命令yum install lrzsz安装webget工具yum -y install wget ----------------------------------- ...

  7. selenium用jquery改变元素属性

    一.jQuery 语法 jQuery 语法是通过选取 HTML 元素,并对选取的元素执行某些操作. 1.基础语法: $(selector).action() 选择符(selector)即," ...

  8. CVE-2010-0249 IE8 UAF漏洞分析

    CVE-2010-0249 [CNNVD]Microsoft Internet Explorer非法事件操作内存破坏漏洞(CNNVD-201001-153) Microsoft Internet Ex ...

  9. Archlinux系统配置学习笔记(一)

    本文档是有关Archlinux系统配置的学习笔记,参考和学习的是Archlinux官方网站上的相应文档:General Recommendations. 这里的配置主要是针对按照官方网站上的文档刚刚完 ...

  10. requireJS2

    requireJS的初步掌握(二) 前面我们讲述了requireJS的一些认知和优点,==>http://www.cnblogs.com/wymbk/p/6366113.html 这章我们主要描 ...