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. MySql数据库资料收集

    1.下载MySQL历史版本 https://downloads.mysql.com/archives/community/ https://downloads.mysql.com/archives/i ...

  2. SQL Server 的字段不为NULL时唯一

    CREATE UNIQUE NONCLUSTERED INDEX 索引名称ON 表名(字段) WHERE 字段 is not null SQL Server 2008+ 支持

  3. js 获取格林尼治时间戳

    昨天在一论坛里看到有朋友问 js 如何获取格林尼治时间戳.不少朋友第一反应是 toGMTString ...确实可以得到格林尼治时间,但不是时间戳.虽然我也没有啥好的方法一步到位的获取,不过至少是获取 ...

  4. 【ORACLE】oracl基本操作笔记

    1.用命令导入导出表 C:\Users\xiang>imp bjlims/bjlims@orcl file="c:\tjlims.dmp" full=y C:\Users\x ...

  5. Oracle 基本操作符

    1.一般操作符 (1)!= 不等于 select empno,ename,job from scott.emp where job!='manager' (2)^= 不等于 select empno, ...

  6. Dream Spark ------spark on yarn ,yarn的配置

    <?xml version="1.0"?> <!-- Licensed under the Apache License, Version 2.0 (the &q ...

  7. ajax调用WebService 不能跨域

    http://www.cnblogs.com/dojo-lzz/p/4265637.html "Access-Control-Allow-Origin":'http://local ...

  8. javaweb笔记三

    //写了注解,就不用在web.xml里进行注册@WebServlet(urlPatterns="/my",name="my",loadOnStartup=1,i ...

  9. SqlServer导入Excel数据

    一:创建数据库: CREATE TABLE IndustrialTownTB ( [ID] [NVARCHAR](36) PRIMARY KEY NOT NULL , IndustrialNewCit ...

  10. hdu 5011 nim博弈 (2014西安网赛E题)

    n堆石子,每次可以选一堆取走至少一个,之后你可以不操作或者把该堆石子分成两堆,每堆至少一个,和还是原来(取完石子后)的石子个数. Sample Input1121 131 2 3 Sample Out ...