题目: You are a coach at your local university. There are nn students under your supervision, the programming skill of the ii-th student is aiai. You have to form kk teams for yet another new programming competition. As you know, the more students are…
题意: 给出 n 个数,选取其中若干个数分别组成至多 k 组,要求每组内最大值与最小值的差值不超过5,求最后被选上的总人数. 题解: 将a[1∼n] 从小到大排序, f[i][j] 表示到第 i 个数为止,已经组成 j 组,最多可以包含多少个数. 那么,考虑第 i 个数选取与否,如果不选,那么 , 如果选,那么必然是第 i 个数所在组人数加上前面那些组人数,假设 p 表示距离 a[i]左侧最远的那个位置(满足 ),这里是指p之前的那些组的人数 题目链接: https://cn.vjudge.ne…
类比背包问题,为每个学生附加一个权重$pos[i]$,意思是选择该学生后,之后可以选择$p[i]~p[i]+5$的学生. 转换公式: $$d[i][j]=max(d[i+1][q],d[i+pos][i]-pos[i])$$ #include<bits/stdc++.h> using namespace std; int p[5005],d[5005][5005],pos[5005]; int n; int f(int i,int q){ if(q==0||i>n)return 0; i…
E. Yet Another Division Into Teams There are n students at your university. The programming skill of the i-th student is ai. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this unive…
题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per test 256 megabytesinput standard inputoutput standard output You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The colo…
On the Bench 两个数如果所有质因子的奇偶性相同则是同一个数,问题就变成了给你n个数, 相同数字不能相邻的方案数. dp[ i ][ j ]表示前 i 种数字已经处理完, 还有 j 个位置需要隔开的方案数. 转移的话, 我们枚举第i + 1种数字分成的段数, 然后枚举有几段插到 j 个空格里面, 然后转移. 最后乘上各种数字个数的阶乘. #include<bits/stdc++.h> #define LL long long #define LD long double #defin…
E. Inverse Coloring time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a square board, consisting of $$$n$$$ rows and $$$n$$$ columns. Each tile in it should be colored either w…