题目链接:http://codeforces.com/contest/808/problem/E 题意:最多有100000个物品最大能放下300000的背包,每个物品都有权值和重量,为能够带的最大权值. 物品重量只有3中.重量为1,2,3. 题解:可以用3分写,这里先不介绍.主要讲一下二分+dp的方法.首先将重量为1,2,3的物品分别存下来, 然后从大到小排序一下.求一下前缀和,先将1,2二分,因为1,2的取法就两种要么取2,要么取两个1代替 2这里就需要二分,比较一下b[mid] and a[…
E. Selling Souvenirs 题意: n件物品,有重量和价值,重量只有三种1,2,3.问取不超过m重量的物品的价值总和最大是多少.(n<=1e5,w<=3e5) 思路: n*w很大,常规01背包不能直接做.考虑到物品重量不超过3,可以按重量分类物品.枚举重量3的物品取的件数,可以发现如果重量2的物品取得多则重量1的物品就得取得少,反之亦然.因此所取重量1,2的物品的价值和与重量2物品取的件数应该满足一个上凸函数的关系,即有一个极值点,那个点就是当前枚举下的1,2物品最大价值和.因此…
传送门 题意 给出n个体积为wi,价值为ci的物品,现在有一个m大的背包 问如何装使得最后背包内的物品价值最大,输出价值 分析 一般的思路是01背包,但n*v不可做 题解的思路 We can iterate on the number of 3-elements we will take (in this editorial k-element is a souvenir with weight k). When fixing the number of 3-elements (let it b…
题目链接:http://codeforces.com/contest/808/problem/D 题意:有一串长度为n的数组,要求选择一个数字交换它的位置使得这串数能够分成两串连续的和一样的数组. 这个数还可以和自己交换位置. 题解:很显然求一下前缀二分每个数看一下能否插入,再求一下后缀二分每个数看一下能否插入. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm…
#include<bits/stdc++.h>using namespace std;int dp[1000007][7][7];int cnt[1000007];int main(){    int n,m;    scanf("%d%d",&n,&m);    int x=0;    for(int i=1;i<=n;i++){        scanf("%d",&x);        cnt[x]++;    }  …
E. Selling Souvenirs time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an op…
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每通过一关后可以选择继续下一关或者时间清0并从第一关开始,先要求通过所有关卡的时间和不能超过R才算彻底通关,问直到彻底通关位置的游戏时间的期望值为多少 分析 二分从头开始通关的用时期望mid 设\(dp[i][j]\)表示通前i关,当前时间为j的期望,倒推期望. 若超时重新开始,则\(dp[i][j]…
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a sequence a consisting of n integers. Find the maximum possible value of (integer remainder of *a**i* divi…
题意: 有n个员工,每个员工完成一件A任务和一件B任务的时间给出,问要完成x件A任务y件B任务所需的最短时间是多少 思路: DP + 二分我也是第一次见到,这个我只能说太难想了,根本想不到. dp[i][j]表示在t时间内前i个人完成j件A任务后所能完成B任务的最大数量. 代码中还有一些注释. //#define LOCAL #include <iostream> #include <cstdio> #include <cstring> using namespace…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4123 题目大意: 给一棵树,n个节点,每条边有个权值,从每个点i出发有个不经过自己走过的点的最远距离Ma[i],有m个询问,每个询问有个q,求最大的连续节点区间长度ans,使得该区间内最大的M[i]和最小的M[j]之差不超过q. 解题思路一: 这套题目好卡时间. 树形dp+二分+单调队列,几个基本的知识点杂糅在一起. 先用树形dp求出从任意一点i出发的Ma[i].两遍dfs,第一遍求出每个节点为根…