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. Verilog 参数化设计

    为了提高模块的重复利用,关键就在于避免硬编码(hard literal),使模块参数化.参数化建模的好处是可以使代码清晰,便于后续维护和修改.只需要修改参数,不用修改其他代码就可以适用于不同的环境中. ...

  2. nl

    -b -b -a 表示不论是否为空行,也同样列出行号 -b -t 如果用空行,空行不要列出行号 -n 列出行号表示方法,主要有3中 -n -n ln 行号显示在屏幕的最左方显示 -n rn 行号显示在 ...

  3. 使用 Azure 创建网络文件系统

    本快速入门介绍了如何使用 Azure 文件存储实现网络文件共享.在本教程中完成的所有操作均符合 1 元试用条件. 本快速入门介绍了如何使用 Azure 文件存储实现网络文件共享.在本教程中完成的所有操 ...

  4. codeforces Gym 100338C Important Roads (重建最短路图)

    正反两次最短路用于判断边是不是最短路上的边,把最短路径上的边取出来建图.然后求割边.注意重边,和卡spfa. 正权,好好的dijkstra不用,用什么spfa? #include<bits/st ...

  5. SQL——SQL语言全部关键字详解

    http://blog.csdn.net/quinnnorris/article/details/71056445 数据库中我们做常用的就是SQL基本查询语言,甚至有些人认为数据库就是SQL,SQL就 ...

  6. Asp.Net Core 入门(十)—— 模型绑定和验证

    模型绑定时将Http请求中的数据映射到控制器操作方法上对应的参数,操作方法中的参数可以是简单类型,如整形,字符串等,也可以是复杂类型,如Product,Order等. Asp.Net Core MVC ...

  7. caffe修改需要的东西

    https://blog.csdn.net/zhaishengfu/article/details/51971768?locationNum=3&fps=1

  8. Nginx代理tcp端口实现负载均衡

    Nginx代理tcp端口实现负载均衡 1.修改配置文件 vi /etc/nginx/nginx.conf 添加如下配置: stream { ###XXX upstream notify {   has ...

  9. 基于Passthru的NDIS开发的个人理解

    这几天对NDIS的学习,基本思路是:首先熟悉理论知识→然后下载一个例子进行研究→最后例子自己模仿扩展→最最后尝试自己写一个新的. Passthru是微软NDIS自己写的一个框架驱动,NDIS开发者可以 ...

  10. javascript设计模式(张容铭)学习笔记 - 照猫画虎-模板方法模式

    模板方法模式(Template Method):父类中定义一组操作算法骨架,而降一些实现步骤延迟到子类中,使得子类可以不改变父类的算法结构的同时可重新定义算法中某些实现步骤. 项目经理体验了各个页面的 ...