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 ...
随机推荐
- Docker快速构建Redis集群(cluster)
Docker快速构建Redis集群(cluster) 以所有redis实例运行在同一台宿主机上为例子 搭建步骤 redis集群目录清单 . ├── Dockerfile ├── make_master ...
- Linux KDE 设置显示桌面的快捷键 win+d
原文链接:http://blog.sina.com.cn/s/blog_4b91893c0100sxxg.html 到KDE下以后发现显示桌面的快捷键被用来显示平铺窗口,在Win下的时候一直用这个快捷 ...
- Django的学习需要掌握的一些基础和初步搭建自己的框架
一.Django的学习需要掌握的一些基础 第一个需要注意的点:客户端发送过来的数据结构组成: 第二个需要注意的点:动态网页和静态网页 静态网页:用户发送请求,服务端找到对应的静态文件返回给浏览器,静态 ...
- iOS之核心动画
.将动画的所有方法封装到一个类里面 MyCAHelper.h #import <Foundation/Foundation.h> #import <QuartzCore/Quartz ...
- git的基本使用命令操作
Linux操作命令行: mkdir - 创建文件夹, cd - 切换文件路径 pwd - 显示文件路径 ls -ah - 可以查看隐藏的文件夹名(.git) cat 文件 ...
- Oracle汇总
1.数据库事务并发会产生那些问题?有哪些隔离级别,分别能够避免什么错误,而无法避免什么错误? a.事务并发会导致三种问题:脏读.不可重复读.幻象读 脏读:读取了未提交的数据 不可重复读:前后读取同一行 ...
- 洛谷 P2872 [USACO07DEC]道路建设Building Roads
题目描述 Farmer John had just acquired several new farms! He wants to connect the farms with roads so th ...
- 洛谷 P1009 阶乘之和
题目描述 用高精度计算出S=1!+2!+3!+…+n!(n≤50) 其中“!”表示阶乘,例如:5!=5*4*3*2*1. 输入输出格式 输入格式: 一个正整数N. 输出格式: 一个正整数S,表示计算结 ...
- 2.add two number
在初始化的时候:ListNode* result;这样就会报runtime error
- EMVS: Event-based Multi-View Stereo 阅读笔记
0. 摘要 EMVS目的:从已知轨迹的event相机,估计半稠密的3D结构 传统的MVS算法目的:从已知视点的图片集,去估计场景的稠密3D结构. EMVS2个固有属性: (1) 当传感器发生相对运 ...