题: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. Windows10 与 WSL(Ubuntu)的文件互访

    从WSL访问win10的文件 > cd /mnt 从win10访问WSL的文件 打开Ubuntu > explorer.exe . (后面的点不要漏掉)

  2. CodeForces - 131C The World is a Theatre(组合数)

    题意:已知有n个男生,m个女生.现在要选t个人,要求有至少4个男生,至少1个女生,求有多少种选法. 分析: 1.展开,将分子中的m!与分母中n!相约,即可推出函数C. #pragma comment( ...

  3. Mac 用终端(命令行)打开vscode编辑器

    1.打开控制面板(⇧⌘P) 2.输入 shell command 在提示里看到 Shell Command: Install ‘code’ command in PATH, 就可以了. 3.使用: c ...

  4. 和为S的连续正序列

    [问题]小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100.但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数).没多久,他就 ...

  5. Java8集合框架——LinkedList源码分析

    java.util.LinkedList 本文的主要目录结构: 一.LinkedList的特点及与ArrayList的比较 二.LinkedList的内部实现 三.LinkedList添加元素 四.L ...

  6. Python说文解字_杂谈09

    1. 元类编程代码分析: import numbers class Field: pass class IntField(Field): # 数据描述符: # 初始化 def __init__(sel ...

  7. dac mssql server

    unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...

  8. 委托、Action、Func使用

    参考 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syste ...

  9. bash字符串处理

    将movie目录下的文件名写到markdown文件中 , 再转html rm index.md ; for f in `find . *.* | sort`; do [ -f $f ] &&a ...

  10. 乳草的侵占(BFS)

    armer John一直努力让他的草地充满鲜美多汁的而又健康的牧草.可惜天不从人愿,他在植物大战人类中败下阵来.邪恶的乳草已经在他的农场的西北部份占领了一片立足之地. 草地像往常一样,被分割成一个高度 ...