Codeforces Round #455 (Div. 2) A-C


A;

A. Generate Login
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.

You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).

As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".

Input

The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.

Output

Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.

Examples
input
harry potter
output
hap
input
tom riddle
output
tomr

【题意】

 求前缀和 和面单词里的字典序最小的;

【思路】

暴力, 数据小,直接暴力所有情况

【代码实现】

#include 
#include 
#include 
#include 

typedef long long ll;
using namespace std;

int main()
{
    string a,b;
    cin>>a>>b;
    vector ans;
    ans.clear();
    for(int i=1;i<=a.length();i++)
    {
        for(int j=1;j<=b.length();j++)
        {
            string temp=a.substr(0,i)+b.substr(0,j);
            //cout<


B;

B. Segments
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be  of them.

You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.

Find the minimal number of layers you have to use for the given N.

Input

The only input line contains a single integer N (1 ≤ N ≤ 100).

Output

Output a single integer - the minimal number of layers required to draw the segments for the given N.

Examples
input
2
output
2
input
3
output
4
input
4
output
6
Note

As an example, here are the segments and their optimal arrangement into layers for N = 4.

Codeforces Round #455 (Div. 2) A-C_第1张图片

123


【思路】

这道题是一道数学规律题,求最小的步数, 题意并没有给出具体的情况,只有

1->1 ,2->3 , 3->4, 4->6,   

推,5->9 ,   找规律  a[n]= 2a[n-1]-2a[n-3]+a[n-4]


【代码实现】

#include 
#include 
#include 
#include 

typedef long long ll;
using namespace std;

int ans[120];

int main()
{
    int n;
    ans[0]=0;
    ans[1]=1;
    ans[2]=2;
    ans[3]=4;
    ans[4]=6;
    for(int i=5;i<=100;i++)
    {
        ans[i]=2*ans[i-1]-2*ans[i-3]+ans[i-4];
       // cout<>n;
    cout<



C

C. Python Indentation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.

We will consider an extremely simplified subset of Python with only two types of statements.

Simple statements are written in a single line, one per line. An example of a simple statement is assignment.

For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.

You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.

Input

The first line contains a single integer N (1 ≤ N ≤ 5000) — the number of commands in the program. N lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.

Output

Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109 + 7.

Examples
input
4
s
f
f
s
output
1
input
4
f
s
f
s
output
2
Note

In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.

simple statement
for statement
    for statement
        simple statement

In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.

for statement
    simple statement
    for statement
        simple statement

or

for statement
    simple statement
for statement
    simple statement

12


【题意】

python 没有缩进

现在给n个字符; f 代表是for循环  ,s代表是单语句。 f后面不能为空,  f , s  缩进表示的形式有多少种

【思路】

DP

把表格写出了,  横为 缩进的个数0,1,2,3,4,5,6,

拿   ffsssfs 示例

0 1 2 3 4 5 6 7 8 9

1 f  1

2 f 0 1

3 s 0 0 1

4 s 1 1 1

5 s 3 2 1

6 f 6 3 1

7 s 0 6 3 1

答案为 0+6+3+1=10;

对于每行  如果上一个是s  可以发现,  上一个的后缀和

如果不是s 那么dp[i][j] = dp[i-1][j-1]


【代码实现】

#include 
#include 
#include 
#include 
#define mem(a,b) memset(a,b,sizeof(a))
#define SHUT std::ios::sync_with_stdio(false)
typedef long long ll;
using namespace std;
const int MAXN=1e5+5;
const int MOD=1e9+7;
char a[MAXN];
int dp[5050][5050];
int main()
{
    SHUT;
    int n;
    cin>>n;
    mem(a,0);
    vectorV[MAXN];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    dp[1][1]=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i-1]=='s')
        {
            ll now=0;
            for(int j=5050;j>=1;j--)
            {
                now=(now+dp[i-1][j])%MOD;
                dp[i][j]=now;
            }
        }
        else
        {
            for(int j=5050;j>=1;j--)
            {
                dp[i][j]=dp[i-1][j-1]%MOD;
            }
        }
    }
    /*for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=10;j++)
        {
            cout<


你可能感兴趣的:(CodeForeces,ACM进阶之路)