Manthan, Codefest 17
2 seconds
256 megabytes
standard input
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).
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 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).
6
tom
lucius
ginny
harry
ginny
harry
NO
NO
NO
NO
YES
YES
3
a
a
a
NO
YES
YES
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 ;
}
2 seconds
256 megabytes
standard input
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.
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 a single integer the maximum value of p·ai + q·aj + r·ak that can be obtained provided 1 ≤ i ≤ j ≤ k ≤ n.
5 1 2 3
1 2 3 4 5
30
5 1 2 -3
-1 -2 -3 -4 -5
12
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 ;
}
2 seconds
256 megabytes
standard input
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.
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 a single integer, the number of ways of giving each vault a type following the conditions modulo 109 + 7.
4 2
1 2
2 3
1 4
1 2
1
3 3
1 2
1 3
2 1
13
3 1
1 2
1 3
1 1
0
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的更多相关文章
- 【codeforces Manthan, Codefest 17 C】Helga Hufflepuff's Cup
[链接]h在这里写链接 [题意] k是最高级别的分数,最高界别的分数最多只能有x个. 1<=k<=m; 和k相邻的点的分数只能小于k; n个点的树,问你每个 ...
- 【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]最大; [题解] /* 有一个要 ...
- 【CF Manthan, Codefest 17 A】Tom Riddle's Diary
[链接]h在这里写链接 [题意] 在这里写题意 [题解] /* Be careful. 二重循环枚举 */ [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/st ...
- 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 ...
- 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 ...
- 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 ...
- Manthan, Codefest 19(Div. 1 + Div. 2)
传送门 A. XORinacci 签到. Code /* * Author: heyuhhh * Created Time: 2020/2/26 9:26:33 */ #include <ios ...
- Manthan, Codefest 16 D. Fibonacci-ish
D. Fibonacci-ish time limit per test 3 seconds memory limit per test 512 megabytes input standard in ...
- 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 ...
随机推荐
- Permutations(copy)
Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the follo ...
- python 基础网络编程2
python 基础网络编程2 前一篇讲了socketserver.py中BaseServer类, 下面介绍下TCPServer和UDPServer class TCPServer(BaseServer ...
- SQL——SQL语言全部关键字详解
http://blog.csdn.net/quinnnorris/article/details/71056445 数据库中我们做常用的就是SQL基本查询语言,甚至有些人认为数据库就是SQL,SQL就 ...
- Javascript 日期格式化
Javascript 日期格式化 需求: 给出:日期 .格式,根据日期格式进行输出. Date.prototype.Format = function (fmt) { //author: meizz ...
- 如何实现第二窗口不显示在windows下面的任务栏中
将要隐藏的窗体的的ShowInTaskBar属性设置为false;就好了
- archlinux alsa安装,音量设置和音量信息保存
1,使用前确认安装了alsa-utils sudo pacman -S alsa-utils2,运行alsamixer调试音量 alsamixer左右键选择调哪个,将Master和PCM按“m”解除静 ...
- Repbase library|divergence rate|self-sequence alignment|genomic rearrangement|cutoffs|breakpoint
(Panda, dog and human repeat comparison):与其他动物比较重复序列 我们使用Repbase 库(重复序列库)+已知的转录原件序列+识别软件,评估出转录原件占比,并 ...
- Linux C++/C开发所必需的一系列工具
系统平台下的开发工具.开发环境各有不同.Linux C++/C开发所必需的一系列工具: 1. vi(vim)文本编辑器一个UNIX世界标准的文本编辑器,简约而强大,不论作为开发人员还是系统管理员,熟练 ...
- poi导出word模板项目实例(一个文件)
在页面上填写值,然后导出到word模板中,并把页面上的值带到模板中,也就是导出word文档,提前有word 的模板形式, 1.jsp 页面 <table class="formTa ...
- ueditor1.4.3.all.js报错
.replace( /<[^>/]+>/g, '' ) 转义符问题! 修改为: .replace( /<[^>\/]+>/g, '' )