题目描述 有\(n\)个物品,每个物品有一个体积\(v_i\),背包容量\(s\).要求选一些物品恰好装满背包且物品个数最少,并在这样的方案中: (1)求出中位数最小的方案的中位数(\(k\)个元素的中位数是从小到大第\(⌊k/2⌋\)个数): (2)求出众数最小的方案的众数: (3)求出极差最小的方案的极差. 解题思路 令每个物品价值为1,求装满时的最小价值,这只需01背包即可,答案即为最小个数\(m\). 对于众数,二分答案并删去多余物品即可. 对于中位数,二分答案,令每个物品价值为\(in…
MG loves string    Accepts: 30    Submissions: 67  Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) 问题描述 MGMG是一个很忙碌的男孩子.今天他沉迷于这样一个问题: 对于一个长度为NN的由小写英文字母构成的随机字符串,当它进行一次变换,所有字符ii都会变成a[i]a[i]. MGMG规定所有a[i]a[i]构成了2626个…
题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只有点权. LYK想把这个图删干净,它的方法是这样的.每次选择一个点,将它删掉,但删这个点是需要代价的.假设与这个点相连的还没被删掉的点是u1,u2,…,uk.LYK 将会增加a[u1],a[u2],…,a[uk]的疲劳值. 它想将所有点都删掉,并且删完后自己的疲劳值之和最小.你能帮帮它吗? 数据范围: 数据保证任意两个点之间最多一条边相连,并且不存在自环. 1<=n,m,ai<=10000…
题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只有点权. LYK想把这个图删干净,它的方法是这样的.每次选择一个点,将它删掉,但删这个点是需要代价的.假设与这个点相连的还没被删掉的点是u1,u2,…,uk.LYK将会增加a[u1],a[u2],…,a[uk]的疲劳值. 它想将所有点都删掉,并且删完后自己的疲劳值之和最小.你能帮帮它吗? 输入格式(god.in) 第一行两个数n,m表示一张n个点m条边的图. 第二行n个数ai表示点权. 接下来m行每行…
#include<iostream> using namespace std; int n; ; ]; long long p[maxn]; long long dp[maxn][maxn]; long long tot; int pre() { ;i<=n;i++) { if(!note[i]) { p[++tot]=i; } ;j<=tot&&i*p[j]<=n;j++) { note[i*p[j]]=; ) { break; } } } } int ma…
A. Mines 每个点能爆炸到的是个区间,线段树优化建图,并求出SCC进行缩点. 剔除所有不含任何$n$个点的SCC之后,最小代价为每个入度为$0$的SCC中最小点权之和,用set维护即可. 时间复杂度$O(n\log n)$. #include<cstdio> #include<algorithm> #include<set> using namespace std; typedef pair<int,int>P; const int N=1000010…
题目链接:https://codeforces.com/contest/1090/problem/A A conglomerate consists of n companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to s…
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these…
题目链接:https://codeforces.com/contest/1090/problem/M There are n houses along the road where Anya lives, each one is painted in one of k possible colors. Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have…
题目链接 很明显的一道完全背包板子题,做法也很简单,就是要注意 这里你可以买比所需多的干草,只要达到数量就行了 状态转移方程:dp[j]=min(dp[j],dp[j-m[i]]+c[i]) 代码如下: #include<cstdio> #include<iostream> #include<cstdlib> #include<iomanip> #include<cmath> #include<cstring> #include<…