Codeforces Round #598 (Div. 3)E(dp路径转移)
题: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路径转移)的更多相关文章
- Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划
Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划 [Problem Description] 给你\( ...
- 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...
- 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 ...
- 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 ...
- 严格递增类的dp Codeforces Round #371 (Div. 1) C dp
http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...
- 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp
http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...
- Codeforces Round #548 (Div. 2) C dp or 排列组合
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...
- Codeforces Round #536 (Div. 2) E dp + set
https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
随机推荐
- POJ 1547:Clay Bully
Clay Bully Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8349 Accepted: 4711 Descri ...
- org.springframework.test.context.junit4.SpringJUnit4ClassRunner
项目中有了spring-test的依赖,里面确实也有 org.springframework.test.context.junit4.SpringJUnit4ClassRunner 此类,但是项目就是 ...
- 洛谷 P2341 [HAOI2006]受欢迎的牛|【模板】强连通分量
题目传送门 解题思路: 先求强联通分量,缩点,然后统计新图中有几个点出度为0,如果大于1个,则说明这不是一个连通图,答案即为0.否则入度为0的那个强连通分量的点数即为答案 AC代码: #include ...
- SSH限制与更改端口、限制ROOT方式登录
ssh中如何配置只允许某个IP以某个账号登录服务器 只要在ssh的配置文件:sshd_config中添加如下一行即可Allowusers username@192.168.1.100上述只允许IP地址 ...
- dp--悬线dp P4147 玉蟾宫
题目背景 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. 题目描述 这片土地被分成N*M个格子,每个格子里写着'R'或者'F ...
- php日期时间戳,日期函数使用
date_default_timezone_get():获得当前php的时区 date_default_timezone_set():设置当前php的时区 date("Y-m-d H-i-s ...
- selenium登陆qq邮箱页面
from selenium import webdriver driver = webdriver.Chrome() driver.get('https://mail.qq.com/cgi-bin/l ...
- python画图嵌入html
#-*- coding=utf-8 -*- import matplotlib import matplotlib.pyplot as plt from io import BytesIO impor ...
- java RSA 加密解密
package com.rsa; import java.security.KeyFactory; import java.security.KeyPair; import java.security ...
- vscode 集成git bash, mingw, mintty 的terminal
设置 右上角打开json文件的设置 输入以下代码: "terminal.external.windowsExec": "D:\\Program Files\\Git\\b ...