A. Tom Riddle's Diary
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.

He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.

Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).

Input

First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list.

Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.

Output

Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.

You can print each letter in any case (upper or lower).

Examples
input
6
tom
lucius
ginny
harry
ginny
harry
output
NO
NO
NO
NO
YES
YES
input
3
a
a
a
output
NO
YES
YES
Note

In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".

直接枚举啦,就是判断出现过没

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
set<string> s;
for (int i = ; i < n; i++)
{
string c;
cin >> c;
if (s.count(c)) puts("YES");
else puts("NO");
s.insert(c);
}
return ;
}
B. Marvolo Gaunt's Ring
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly x drops of the potion he made.

Value of x is calculated as maximum of p·ai + q·aj + r·ak for given p, q, r and array a1, a2, ... an such that 1 ≤ i ≤ j ≤ k ≤ n. Help Snape find the value of x. Do note that the value of x may be negative.

Input

First line of input contains 4 integers n, p, q, r ( - 109 ≤ p, q, r ≤ 109, 1 ≤ n ≤ 105).

Next line of input contains n space separated integers a1, a2, ... an ( - 109 ≤ ai ≤ 109).

Output

Output a single integer the maximum value of p·ai + q·aj + r·ak that can be obtained provided 1 ≤ i ≤ j ≤ k ≤ n.

Examples
input
5 1 2 3
1 2 3 4 5
output
30
input
5 1 2 -3
-1 -2 -3 -4 -5
output
12
Note

In the first sample case, we can take i = j = k = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.

In second sample case, selecting i = j = 1 and k = 5 gives the answer 12.

Create a dynamic programming table of size n·3. In this, dp[i][0] stores maximum of value p·ax for x between 1 and i. Similarly dp[i][1] stores the maximum value of p·ax + q·ay such that x ≤ y ≤ i and dp[i][2] stores maximum value of p·ax + q·ay + r·az for x ≤ y ≤ z ≤ i.

To calculate the dp:

dp[i][0] = max(dp[i - 1][0], p·ai)

dp[i][1] = max(dp[i - 1][1], dp[i][0] + q·ai)

dp[i][2] = max(dp[i - 1][2], dp[i][1] + r·ai)

The answer will be stored in dp[n][2]

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+;
ll a[N];
ll ans[];
int main()
{
ll n,p,q,r;
cin>>n>>p>>q>>r;
for(int i=; i<=n; i++)
cin>>a[i];
for(int i=; i<; i++)
ans[i]=-9e18;
for(int i=; i<=n; i++)
{
ans[]=max(ans[],a[i]*p);
ans[]=max(ans[],ans[]+q*a[i]);
ans[]=max(ans[],ans[]+r*a[i]);
}
cout<<ans[]<<endl;
return ;
}
C. Helga Hufflepuff's Cup
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Harry, Ron and Hermione have figured out that Helga Hufflepuff's cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatrix's family vault in Gringott's Wizarding Bank.

The Wizarding bank is in the form of a tree with total n vaults where each vault has some type, denoted by a number between 1 to m. A tree is an undirected connected graph with no cycles.

The vaults with the highest security are of type k, and all vaults of type k have the highest security.

There can be at most x vaults of highest security.

Also, if a vault is of the highest security, its adjacent vaults are guaranteed to not be of the highest security and their type is guaranteed to be less than k.

Harry wants to consider every possibility so that he can easily find the best path to reach Bellatrix's vault. So, you have to tell him, given the tree structure of Gringotts, the number of possible ways of giving each vault a type such that the above conditions hold.

Input

The first line of input contains two space separated integers, n and m — the number of vaults and the number of different vault types possible. (1 ≤ n ≤ 105, 1 ≤ m ≤ 109).

Each of the next n - 1 lines contain two space separated integers ui and vi (1 ≤ ui, vi ≤ n) representing the i-th edge, which shows there is a path between the two vaults ui and vi. It is guaranteed that the given graph is a tree.

The last line of input contains two integers k and x (1 ≤ k ≤ m, 1 ≤ x ≤ 10), the type of the highest security vault and the maximum possible number of vaults of highest security.

Output

Output a single integer, the number of ways of giving each vault a type following the conditions modulo 109 + 7.

Examples
input
4 2
1 2
2 3
1 4
1 2
output
1
input
3 3
1 2
1 3
2 1
output
13
input
3 1
1 2
1 3
1 1
output
0
Note

In test case 1, we cannot have any vault of the highest security as its type is 1 implying that its adjacent vaults would have to have a vault type less than 1, which is not allowed. Thus, there is only one possible combination, in which all the vaults have type 2.

这个题我有点懵

树形dp,类似于染色吧

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
const int MD=1e9+;
typedef long long LL;
int n, m, k, x;
int f[N][][], g[][];
vector < int > V[N];
void DFS(int u, int fa)
{
f[u][][] = k - ;
f[u][][] = ;
f[u][][] = m - k;
for(auto &v: V[u])
{
if(v == fa) continue;
DFS(v, u);
memset(g, , sizeof(g));
for(int i = x; i>=; --i)
for(int j=x-i; j>=; --j)
{
g[i + j][] = (g[i + j][] + 1LL * f[u][i][] * f[v][j][]) % MD;
g[i + j][] = (g[i + j][] + 1LL * f[u][i][] * f[v][j][]) % MD;
g[i + j][] = (g[i + j][] + 1LL * f[u][i][] * f[v][j][]) % MD;
g[i + j][] = (g[i + j][] + 1LL * f[u][i][] * f[v][j][]) % MD;
g[i + j][] = (g[i + j][] + 1LL * f[u][i][] * f[v][j][]) % MD;
g[i + j][] = (g[i + j][] + 1LL * f[u][i][] * f[v][j][]) % MD;
}
for(int i = ; i <= x; ++i)
for(int j = ; j < ; ++j)
f[u][i][j] = g[i][j];
}
}
int main()
{
scanf("%d %d", &n, &m);
for(int i = ; i < n; ++i)
{
int u,v;
scanf("%d %d", &u, &v);
V[u].push_back(v);
V[v].push_back(u);
}
scanf("%d %d", &k, &x);
DFS(, );
int ans = ;
for(int i = ; i <= x; ++i)
for(int j = ; j < ; ++j)
ans = (ans + f[][i][j]) % MD;
printf("%d\n", ans);
return ;
}

Manthan, Codefest 17的更多相关文章

  1. 【codeforces Manthan, Codefest 17 C】Helga Hufflepuff's Cup

    [链接]h在这里写链接 [题意]     k是最高级别的分数,最高界别的分数最多只能有x个.     1<=k<=m;     和k相邻的点的分数只能小于k;     n个点的树,问你每个 ...

  2. 【CF Manthan, Codefest 17 B】Marvolo Gaunt's Ring

    [链接]h在这里写链接 [题意] 给你n个数字; 让你在其中找出三个数字i,j,k(i<=j<=k); 使得p*a[i]+q*a[j]+r*a[k]最大; [题解] /*     有一个要 ...

  3. 【CF Manthan, Codefest 17 A】Tom Riddle's Diary

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] /* Be careful. 二重循环枚举 */ [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/st ...

  4. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造

    Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造 [Problem Descripti ...

  5. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组

    Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组 [Pro ...

  6. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构

    Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构 [Problem ...

  7. Manthan, Codefest 19(Div. 1 + Div. 2)

    传送门 A. XORinacci 签到. Code /* * Author: heyuhhh * Created Time: 2020/2/26 9:26:33 */ #include <ios ...

  8. Manthan, Codefest 16 D. Fibonacci-ish

    D. Fibonacci-ish time limit per test 3 seconds memory limit per test 512 megabytes input standard in ...

  9. Manthan, Codefest 16(B--A Trivial Problem)

    B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. 关于.NET .cs后台提示并进行页面跳转代码

    在后台.CS页面中植入下面代码 string url = "<script>alert('xxx');window.location.href='"xxx.html&q ...

  2. drupal中文安装指导

    (注:drupal6中文包放在profiles/default/translations下,drupal7放在profiles/standard/translations下) Drupal 6 中文安 ...

  3. POJ 3461 kmp

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40168   Accepted: 16135 Descript ...

  4. 学习php中的mysql()函数

    1.mysql_connect(1,2,3):连接数据库服务器语句,一般常用这三个参数(1)数据库服务器地址,(2)用户名,(3)密码:常与die()(或者exit())函数结合使用:die()函数用 ...

  5. Nengo 神经网络

    Nengo被加拿大滑铁卢大学的神经学家和软件工程师表示,这是迄今为止产生的世界上最复杂.最大规模的人类大脑模型模拟.这个名叫Spaun的大脑由250万 个模拟神经元组成,它能执行8种不同类型的任务.这 ...

  6. 讲课笔记3——浮动、margin失效的问题、默认样式重置

    EO:搜索引擎优化,一般在网页里面只写一个h1标签,搜索引擎可以通过该h1标签里面的内容搜索你所写的网页(a标签和img标签最好写上title属性)标准写法: .logo { text-decorat ...

  7. Python 类变量,成员变量,静态变量,局部变量

    局部 class TestClass(object): val1 = 100 def __init__(self): self.val2 = 200 def fcn(self,val = 400): ...

  8. Java Miniui实现批量上传文件demo 201906221520

    可能需要的jar包: 需要miniui(类似easyui). Test2019062201.jsp <%@ page language="java" contentType= ...

  9. ArcMap所有Command GUID

    The information in this topic is useful if you're trying to programmatically find a built-in command ...

  10. shell脚本,按行读取文件的几种方法。

    第一种方法用while实现按读取文件.[root@localhost wyb]# cat a.txt 第一行 aaaaaa 第二行 bbbbbb 第三行 cccccc 第四行 dddddd 第五行 e ...