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 ...
随机推荐
- sql server 时间查询
select CONVERT(varchar, getdate(),8 ) --获取当前时间时分14:13:59 select CONVERT(varchar, getdate(),23 ) - ...
- 12.JAVA-基本数据类型的包装类操作
1.基本数据类型的包装类 java是一个面向对象编程语言,也就是说一切操作都要用对象的形式进行.但是有个矛盾: 基本数据类型(char,int,double等)不具备对象特性(不携带属性和方法) 这样 ...
- PostgreSQL函数如何返回数据集 [转]
PostgreSQL函数如何返回数据集 以下主要介绍PostgreSQL函数/存储过程返回数据集,或者也叫结果集的示例. 背景: PostgreSQL里面没有存储过程,只有函数,其他数据库里的这两个对 ...
- spring boot & mybatis集合的坑
因为是使用的mybatis逆向工程自动生成的实体类和dao层,然后在读取某一个表的content字段时出现问题. 问题描述:在mysql数据库里可以直接查询到这个字段的内容,但是使用java相关的方法 ...
- Ubuntu16.04 + cuda8.0 + GTX1080安装教程
1. 安装Ubuntu16.04 不考虑双系统,直接安装 Ubuntu16.04,从 ubuntu官方 下载64位版本: ubuntu-16.04-desktop-amd64.iso . 在MAC下制 ...
- apache安装报错
libtool: install: error: cannot install `libaprutil-1.la' to a directory not ending /some_directory ...
- 洛谷 P1168 中位数
题目描述 给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], A[3], …, A[2k - 1]的中位数.[color=red]即[/color] ...
- PostgressSQL-Installation
安装 sudo apt install -y postgresql 自动生成一个名为 postgres 的 Linux 系统用户 $ finger postgres Login: postgres N ...
- kafka 安装以及测试
1,下载kafka 并进行解压 http://mirrors.cnnic.cn/apache/kafka/0.8.1.1/kafka_2.9.2-0.8.1.1.tgz 2,启动Zookeeper ...
- DAG上的动态规划---嵌套矩形(模板题)
一.DAG的介绍 Directed Acyclic Graph,简称DAG,即有向无环图,有向说明有方向,无环表示不能直接或间接的指向自己. 摘录:有向无环图的动态规划是学习动态规划的基础,很多问题都 ...