题:https://codeforces.com/contest/1256/problem/E

题意:给一些值,代表队员的能力值,每组要分3个或3个以上的人,然后有个评价值x=(队里最大值-最小值),问最小的∑x是多少,以及输出方案

学习粗:https://www.cnblogs.com/Lubixiaosi-Zhaocao/p/11797744.html

dp路径转移

#include<bits/stdc++.h>
using namespace std;
const int M=2e5+;
struct node{
int val,id;
}a[M];
int dp[M];
int ans[M],pre[M];
bool cmp(node p,node q){
return p.val<q.val;
}
int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i].val),a[i].id=i;
sort(a+,a++n,cmp);
memset(dp,0x3f,sizeof(dp));
dp[]=;
pre[]=-;
for(int i=;i<=n;i++){
for(int j=;j<=;j++){
if(i-j>=&&dp[i-j]+a[i].val-a[i-j+].val<dp[i]){
pre[i]=i-j;
dp[i]=dp[i-j]+a[i].val-a[i-j+].val;
}
}
}
int tot=;
for(int i=n;i>=;i=pre[i]){
tot++;
for(int j=i;j>pre[i];j--)
ans[a[j].id]=tot;
}
printf("%d %d\n",dp[n],tot);
for(int i=;i<=n;i++)
printf("%d ",ans[i]);
return ;
}

Codeforces Round #598 (Div. 3)E(dp路径转移)的更多相关文章

  1. Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划

    Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划 [Problem Description] 给你\( ...

  2. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

  3. Codeforces Round #598 (Div. 3) E. Yet Another Division Into Teams dp

    E. Yet Another Division Into Teams There are n students at your university. The programming skill of ...

  4. Codeforces Round #598 (Div. 3) C. Platforms Jumping 贪心或dp

    C. Platforms Jumping There is a river of width n. The left bank of the river is cell 0 and the right ...

  5. 严格递增类的dp Codeforces Round #371 (Div. 1) C dp

    http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...

  6. 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp

    http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...

  7. Codeforces Round #548 (Div. 2) C dp or 排列组合

    https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...

  8. Codeforces Round #536 (Div. 2) E dp + set

    https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...

  9. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

随机推荐

  1. promise核心6 自定义promise

    1.定义整体结构(不写实现) 定义一个自己的promise的库 lib(库的简写) 一个js文件.一个js模块(不能用es6  也不能commjs)(用es5模块语法 ) 匿名函数自调用.IIFE ( ...

  2. Window NodeJs安装

    1.下载NodeJs 官网下载地址:http://nodejs.cn/download/ ​ 2.安装 双击,全程next安装. 安装完成,在cmd下面执行查看版本命令,命令如下 C:\Users\A ...

  3. Linux基础应用

    Linux刚面世时并没有图形界面,因此所有的操作全靠命令完成,如磁盘操作.文件读取.目录操作.进程管理.文件权限等都要通过命令完成.且在职场中,大量的服务器维护都是通过远程命令来完成. 常用的7个命令 ...

  4. Windb实践之Script Command

    1.输出参数 .echo The first argument is ${$arg1}. .echo The fifth argument is ${$arg5}. .echo The fourth ...

  5. 简单LCS HDU_1503

    学了一下最长公共子串,它是属于dp里面的 dp=max{(i,j-1),(i-1,j),(i-1,j-1)+d}问题,不得不说,规划方向确实厉害,当然这只适用于两个字符串匹配的问题,n个字符串的话,我 ...

  6. sqlmap简单流程使用

    -u “(url)” 1.判断可注入的参数 2.判断可以用那种SQL注入技术来注入 3.识别出哪种数据库 4.根据用户选择,读取哪些数据 sqlmap支持五种不同的注入模式: 1.基于布尔的盲注,即可 ...

  7. 吴裕雄--天生自然 JAVASCRIPT开发学习:测试 jQuery

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. CodeForces - 350B(反向建图,)

    B - Resort CodeForces - 350B B. Resort time limit per test 2 seconds memory limit per test 256 megab ...

  9. Block实现代理/通知效果

    例子1:A控制器->跳转—>B控制器 , 假设想从B控制器回传数组给A控制器 实现:B控制器.h文件定义一个block参数,.m文件执行block,A控制器设置block内容 B.h文件/ ...

  10. PAT A1001-A1004

    题集通道:https://pintia.cn/problem-sets/994805342720868352/problems/type/7 A1001 :  A+B Format (20 point ...