主题链接:点击打开链接 为了让球队后,删除是合法的.也就是说,对于每一个车辆, l+r+c 一样,按l+r+c分类. 然后dp一下. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <math.h> #include <set> #include <vector> #include <map&…
D. Don't fear, DravDe is kind time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A motorcade of n trucks, driving from city «Z» to city «З», has approached a tunnel, known as Tunnel of Horror…
Brief Intro: 对于四元组(v,c,l,r),求其子序列中v最大的和,并使其满足: 1.Ci+Li+Ri相同 2.L1=0,Rn=0 3.Li=Sigma(C1...Ci-1) Solution: 算是有条件约束的DP吧 设dp[k]为选到k且选k的最大值 对于每个条件,我们这样处理: 1.将所有数据按Ci+Li+Ri的和进行分组处理 2.当Li=0时,将其视为起点:当Ri=0时,用dp[i]去更新res 3.此条件可转换为:仅当Lp=Lq+Cq时,dp[p]可由dp[q]转移而来 于…
补一篇以前的扩展欧几里得的题,发现以前写错了竟然也过了,可能数据水??? 这个题还是很有意思的,和队友吵了两天,一边吵一边发现问题??? L. Knights without Fear and Reproach http://codeforces.com/gym/100812/problem/L time limit per test 2.0 s memory limit per test 256 MB input standard input output standard output Th…
题目传送门:http://codeforces.com/problemset/problem/28/D 题意:给你$N$个物品,每个物品有其价格$P_i$,之前必须要买的物品价格和$L_i$,之后必须要买的物品价格和$R_i$和价值$W_i$.试给出一种物品的选择方案,使得满足所有选择的物品的条件且选择物品的价值和最大(物品的选择顺序必须要与原来的顺序相同).$N \leq 10^5 , P , L , R \leq 10^5 , W \leq 10^4$ 像背包DP,所以就是背包DP(雾 我们…
传送门 Description 一个有N辆卡车的车队从城市Z驶向城市3,来到了一条叫做"恐惧隧道"的隧道.在卡车司机中,有传言说怪物DravDe在那条隧道里搜寻司机.有些司机害怕先走,而其他人则害怕后走.但让我们考虑一般情况,每辆卡车用四个数字描述: •v,卡车的价值,包括乘客和货物 •c,乘客数量,包括司机本人 •l,当前辆卡车之前应该进入的隧道的总人数,这样,当前司机就可以克服他的恐惧(如果怪物出现在那辆车前面,它会先吃掉他们) •r,当前辆卡车之后应该进入的隧道的总人数,这样,当…
题目链接:http://codeforces.com/problemset/problem/216/D 题意: 对于一个梯形区域,假设梯形左边的点数!=梯形右边的点数,那么这个梯形为红色.否则为绿色, 问: 给定的蜘蛛网中有多少个红色. 2个树状数组维护2个线段.然后暴力模拟一下,由于点数非常多但须要用到的线段树仅仅有3条,所以类似滚动数组的思想优化内存. #include<stdio.h> #include<iostream> #include<string.h> #…
主题链接:点击打开链接 意甲冠军:特定n*m矩阵 X代表色 .代表无色 随着x*y形刷子去涂色. 刷子每次能够→或↓移动随意步. 若可以染出给定的矩阵,则输出最小的刷子的面积 若不能输出-1 思路: 先找到连续最小的x,y 由于至少一个边界和x或y相等,所以枚举(x,i) 和 (i,y)就能够了. #pragma comment(linker, "/STACK:102400000,102400000") #include <stdio.h> #include <ios…
题目链接:点击打开链接 给定n表示有n个格子 以下每一个格子为O的概率是多少. 对于一段连续 x 个O的价值就是 x*x ; 问: 获得的价值的期望是多少. 思路: 把公式拆一下.. #include <cstdio> const int N = 100005; double dp[N][2], p[N]; int main(){ int n; scanf("%d", &n); for(int i = 1; i <= n; i ++) { scanf(&quo…
传送门 题意:\(n\)个位置,每个位置有价值\(v_i\)和重量\(p_i\),要选出一些位置,如果要选位置\(i\),那么前面选的重量之和要为\(l_i\),后面选的重量之和要为\(r_i\),求一个方案使得价值和最大 这个限制很舒服,可以设\(f_i\)为从前面开始选,选第\(i\)个的最大价值,转移枚举前面的\(j\),如果能从\(j\)转移过来,根据条件,要求\(l_i=l_j+p_i\&\&r_i=r_j-p_i\),记个转移前缀就可以输出方案了 但是这样还不优,我们可以发现对…
题意:按顺序给出一个各内角均为120°的六边形的六条边长,求该六边形能分解成多少个边长为1的单位三角形. 把单位三角形面积看做1,实际上就是求六边形面积.随便找六边形的三条互相不相邻的边,分别以这三条边为基础向外扩展一个等边三角形.就可以将原六边形补成一个大等边三角形,然后用大等边三角形面积减去补上的3个小等边三角形面积就是原来六边形的面积. 而等边三角形面积非常easy.就是边长的平方(实际就是边长为n的等边三角形能分解成n^2个边长为1的单位三角形,画个图就能理解了). #include <…
http://codeforces.com/problemset/problem/743/D 题意:求最大两个的不相交子树的点权和,如果没有两个不相交子树,那么输出Impossible. 思路:之前好像也做过这种类型的题目啊,知道是树形DP,但是不知道怎么保证两个不相交.看别人代码之后, 在DFS回溯的时候, void dfs(int u, int fa) { sum[u] = w[u]; for(int i = head[u]; ~i; i = edge[i].nxt) { int v = e…
Coloring Trees Problem Description: ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n fr…
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory limit per test 256 megabytes 问题描述 Manao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a play…
题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 secondmemory limit per test 256 megabytes 问题描述 Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends A…
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase Engl…
D. Fox And Jumping 题目连接: http://codeforces.com/contest/510/problem/D Description Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at…
B. Maximum Submatrix 2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/375/B Description You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is…
题目链接: http://codeforces.com/contest/677/problem/D 题意: 让你求最短的从start->...->1->...->2->...->3->...->...->p的最短路径. 题解: 这题dp的阶段性还是很明显的,相同的值得方格为同一个阶段,然后求从阶段1->2->3...->p的阶段图最短路. 初始化所有a[x][y]==1的格子为起始点到(x,y)坐标的距离. 方程式为dp[x1][y1…
题目链接: http://codeforces.com/contest/378/problem/E 题意: dota选英雄,现在有n个英雄,m个回合,两支队伍: 每一回合两个选择: b 1,队伍一ban掉一个英雄,或是跳过这个回合 p 1,队伍1选一个英雄 现在每个队伍都是最优决策,问最后队伍一的英雄实力和-队伍二的英雄实力和. 题解: 状压dp,决策要倒过来做,也就是dp出后面回合的决策的基础上设计出对自己当前回合对自己最有利的决策.. 注意:只有top m的英雄有可能被选,其他的都不可能被选…
题目链接:http://codeforces.com/problemset/problem/429/B 给你一个矩阵,一个人从(1, 1) ->(n, m),只能向下或者向右: 一个人从(n, 1) ->(1, m),只能向上或者向右.必须有一个相遇点, 相遇点的值不能被取到, 问两个人能得到的最大路径和是多少? dp[i][j]:表示从一个点出发的最大值:先预处理从(1,1) (1,m) (n,1) (n,m)四个点出发的4个dp最大值.然后枚举所有的点,但是这个点不能在边缘,考虑枚举点不够…
B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B Description Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (p…
E. LIS of Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem/E Description The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence.…
D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/D Description While Duff was resting in the beach, she accidentally found a strange array b0, b1, ..., bl - 1 consisting of l positive integers. Th…
F. Bulbo Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/F Description Bananistan is a beautiful banana republic. Beautiful women in beautiful dresses. Beautiful statues of beautiful warlords. Beautiful stars in…
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Robots are becoming more and more popular. They are used nowadays not only in manufacturing plants, but also at home. One programmer wit…
B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/B Description You are given a sequence of numbers a1, a2, ..., an, and a number m. Check if it is possible to choose a non-empty subsequence aij such…
http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35  36组数据 然后參考答案了,然后----网上一份题解 大意: 给出一个带权有向图,求经过的边权绝对上升的最长路径(可能是非简单路径,就可以能经过一个点多次)所包括的边数. 题解: 对边按权值排序后,从小到大搞. 设q[x]为已经搞过的边组成的以x点为终点的最长路径包括的边数. 设当前边e[i]为从u到v的边,…
Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input The first and only line contains a single integer mm (1≤m≤100000,1≤m≤100000). Output Print a single integer — the expected length of the array aa writte…
题目链接:https://codeforces.com/contest/55/problem/D 题目大意:给你一段区间[l,r],要求这段区间中可以整除自己每一位(除0意外)上的数字的整数个数,例如15,因为15既可以整除1也可以整除5,所以15符合要求. (1 ≤ li ≤ ri ≤ 9 ·1018). Examples input Copy 11 9 output Copy 9 input Copy 112 15 output Copy 2 解题思路:很明显的数位dp,首先我们可以想一个数…