Codeforces Round #523 (Div. 2) 题目一览表 来源 考察知识点 完成时间 A Coins cf 贪心(签到题) 2018.11.23 B Views Matter cf 思维??? 2018.11.24 C Multiplicity cf dp 2018.11.27 D TV Shows cf 贪心+multiset 2018.12.2…
#include<bits/stdc++.h>using namespace std;long long a[100007];long long dp[1000007];const int mod=1e9+7;int main(){    int n;    scanf("%d",&n);    dp[0]=1;    for(int i=1;i<=n;i++)        scanf("%lld",&a[i]);    for(…
传送门 https://www.cnblogs.com/violet-acmer/p/10005351.html 题意: 给定一数组a[],从a[ ]中除去任意个元素得到b[ ],求能形成多少“好序列”: 好序列的定义是:对于任意的 i 有 b[i]%i == 0(1 ≤ i ≤ size_b[ ]). 题解: 相关变量解释: int n; int a[maxn]; int dp[maxn];//dp[i] : 下标i处可以获得的最大的"好序列" int factor[maxn];//…
http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型,最普遍的方法就是把严格递增给变为递增就好了,所以我们对所有的a进行处理,a[i]-=i,然后再dp. 我们对dp进行如下的定义:定义dp[i][j],dp[i][j]表示前i个数,1~i-1个数的val都<=b[j],目前第i个数修改成b[j](即第j大的数),所需要的最小花费dp[i][j] =…
http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定义数组b[i]=a[i%n].然后数组b的最长的lis为k,问能有几组<=k的lis 条件如下: ①序列长度>=1并且<=k ②序列在每一块长度为n的数组中只能选择一个数,且选择的必须是连续的块 ③序列是不严格的单调递增 思路:主要是看这个人的http://m.blog.csdn.net/a…
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个序列就是好的,问有多少个好的序列 题解 黑边不连,红边连,假如两个点不在同一并查集,那么一定经过黑边 定义\(dp[i][j][k]\)为选择前i个点,起始点为j,是否已经经过黑边(k)的方案数 \(dp[i-1][j][0]*(n-N[fin(j)])+dp[i-1][j][1]*n - > dp…
https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_i\)后才能领取下一个红包,每个红包价值\(w_i\),对方假如有机会领取红包他一定会领取,你有m次阻止对方领取的机会,问对方最少可以拿到多少红包 题解 定义dp[i][j]为前i秒用了j次机会让对方拿到最小价值的红包 \(dp[i][j] - > dp[i+1][j+1]\) 假如使用阻止 \(d…
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(abs(i-j)<h[i]\),那么向j方向推倒i,j也会倒,问选择任意数量骨牌向任意方向推到,使得全部骨牌都倒下的代价最小 题解 连锁反应可以用单调栈或者链表模拟 定义dp[i]为推倒a[i,m]的最小代价 对于每个i,有两种选择: 向左推:\(dp[l[i]+1]=min(dp[l[i]+1],dp[…
https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2. 压缩一个串,条件是这个串是前面整个串的连续子串,代价为b 题解 n<=5000 定义dp[i]为压缩前i个字符的代价,则答案为dp[n] dp[i]=min(dp[i-1]+a,min(dp[j]+b)(即[j+1,i]为[1,j]的子串)) 用字符串哈希处理判定一个串是否为前面的子串 坑点 串ab…
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the…
题:https://codeforces.com/contest/1061/problem/C 题意:给你一个序列,我们求他们子序列的个数,这个子序列有个限制就是每一个子序列上的值都必须是能整除他的下标,问有多少个 分析:考虑dp,我们先考虑二维的dp,定义dp[i][j]表示前i个数中,能从中提取出j个”好“序列,所以dp[i][j]就可以从dp[i-1][j-1]+dp[i-1][j]得来(前提是a[i]%j==0).显然a[i]%j!=0时dp[i][j]=dp[i-1][j] 但这样写会…
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immedi…
数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<vector> using namespace std; #define N 1000100 #defin…
C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on n−2n−2 intermediate planet…
C. Multiplicity 题目链接:https://codeforc.es/contest/1061/problem/C 题意: 给出一串数,问它的“好序列“有多少.好序列的定义是,首先是一个子序列(顺序可以打乱),其次,序列相应位置的数可以除尽该位置编号. 题解:这题是dp,我没有想到,主要是状态的定义. 定义dp(i,j):在a1,a2...ai中长度为j的好序列的个数,这样dp转移方程就为:if ai%j==0:  dp(i,j)=dp(i-1,j-1)+dp(i-1,j)  , e…
https://codeforces.com/contest/1061/problem/E 题意 有n个点(<=500),标记第i个点的代价a[i],然后分别在这n个点建两棵树,对于每颗树的每个点来说,都有一个p[i],代表他的子树中被标记的点的个数需要等于p[i],请你选择需要标记的点,使得可以满足上述两棵树的要求,并且使得代价最大,输出最大的代价或者-1(不存在) 思路 这道题难在建图 首先考虑子树问题,是否选择每个节点对他的子孙节点没有影响,但是对他自身及其祖先节点有影响,注意p[i]=0…
https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每次询问,a,b,c三个点,会返回b是否在a,c之间的路径上 思路 粗略看了下询问次数,可以知道,你最多可以询问60对不同的点,每对点遍历n个点,可以知道n个点在不在这两个点的中间 一开始的思路是,随机找两个点,遍历所有点,然后记录在他们中间的点,在里面再找两个点,继续上述操作,知道剩下一个点,但是假设某一…
A. Coins Water. #include <bits/stdc++.h> using namespace std; int n, s; int main() { while (scanf("%d%d", &n, &s) != EOF) { ; ; --i) while (s >= i) { ++res; s -= i; } printf("%d\n", res); } ; } B. Views Matter Solved.…
D. Palindromic characteristics time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is t…
B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments…
一般这种要倒着来. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define y1 skldjfskldjg #define y2 skldfjsklejg using namespace std; ; ; const int inf = 0x3f3f3f3f; cons…
A. Secrets Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/333/problem/A Description Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has…
Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day…
B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters…
以为是组合,后来看着像数位dp,又不知道怎么让它不重复用..然后就没思路 了. 其实状压就可以了 状压是可以确定一个数的使用顺序的 利用01也可以确定所有的数的使用以及不重复 dp[i+1<<e][(j*10+p[e])%m]+=dp[i][j]; 排下序去掉重复的 或者最后除去每个数出现的次数 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #…
E. Pashmak and Graph Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem. You are…
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output — This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii-chan! With h…
题意:给出n个电视节目的起始和结束时间  并且租一台电视需要x +y*(b-a)  [a,b]为时段 问完整看完电视节目的最小花费是多少 思路:贪心的思想 情况1 如果新租一台电视的花费<=在空闲电视上面看节目 那么肯定新租电视 情况2 否则就直接在空闲电视上看 就好 模拟难(QAQ): 这里使用多重集合模拟   先把所有时间的pair(结束时间,开始时间) 放入多重集里面 然后开一个数组以l 从小到大排序 从数组小到大 枚举  在多重集里面找离终点最近的那个点 如果符合情况1 那么就删去 找到…
传送门 https://www.cnblogs.com/violet-acmer/p/10005351.html 题意: 有n个节目,每个节目都有个开始时间和结束时间. 定义x,y分别为租电视需要的花费和看电视需要的花费(应该是花的电费,哈哈). 加入某电视节目的播放区间是[a,b],那么看完这个节目需要的总花费为x+(b-a)*y. 如果有其他节目的播放区间是[b,c],那么便不能和[a,b]的节目用同一个电视看. 求看完所有电视节目所需要的最少花费. 题解: 这应该是道贪心题. 对于每个节目…
传送门 https://www.cnblogs.com/violet-acmer/p/10005351.html 这是一道贪心题么???? 题意: 某展览馆展览一个物品,此物品有n堆,第 i 堆有a[ i ]个正方块,问最多可以去除多少个正方块,使得其俯视图与右视图的保持不变. 并且去除某正方块a下方的正方块时,是不会导致a方块下降的(无重力). 题解: 相关变量解释: int n,m; ll sum;//所有的方块 int a[maxn];//a[i] : 第i堆有a[i]个正方块 int i…