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有限. 我们可以 ...
随机推荐
- JMS学习(五)--ActiveMQ中的消息的持久化和非持久化 以及 持久订阅者 和 非持久订阅者之间的区别与联系
一,消息的持久化和非持久化 ①DeliveryMode 这是传输模式.ActiveMQ支持两种传输模式:持久传输和非持久传输(persistent and non-persistent deliver ...
- JavaScript内部原理实践——真的懂JavaScript吗?(转)
通过翻译了Dmitry A.Soshnikov的关于ECMAScript-262-3 JavaScript内部原理的文章, 从理论角度对JavaScript中部分特性的内部工作机制有了一定的了解. 但 ...
- Linux - trap 命令
trap 命令用于指定在接收到信号后将要采取的动作,常见的用途是在脚本程序被中断时完成清理工作.当shell接收到sigspec指定的信号时,arg参数(命令)将会被读取,并被执行. trap 信号参 ...
- Android getScrollX()详解
在开发中相信大家在自定义View时会时不时的使用getScrollX()方法,为了便于之后的开发工作,本篇博客主要记录了我对getScrollX()方法的理解. getScrollX:Return t ...
- 深入了解mitmproxy(二)
主题 修改request或者response内容 介绍 mitmdump无交互界面的命令,与python脚本对接,来源于mitmproxy支持inline script,这里的script指 ...
- 『实践』Yalmip+Ipopt+Cplex使用手册
Yalmip+Ipopt+Cplex使用手册 1.软件版本 Cplex 12.6.2,Matlab R2014a,Ipopt 3.12.9,Yalmip 2.Cplex添加方法 官方下载地址: htt ...
- sys和os模块
一 sys 用于python解释器相关的操作 #!/usr/bin/env python # coding=utf-8 import time import sys def view_bar(num, ...
- android 8.0变更
Android 8.0 行为变更 Android 8.0 除了提供诸多新特性和功能外,还对系统和 API 行为做出了各种变更.本文重点介绍您应该了解并在开发应用时加以考虑的一些主要变更. 其中大部分变 ...
- spring-web.xml 模板
ssm模板 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:/ ...
- 【转】MySQL安全配置介绍
一.前言 很多文章中会说,数据库的权限按最小权限为原则,这句话本身没有错,但是却是一句空话.因为最小权限,这个东西太抽象,很多时候你并弄不清楚具体他需要哪些权限. 现在很多mysql用着root账户在 ...