UESTC 2016 Summer Training #6 Div.2
我好菜啊..
给出 n 个数,分成m组,每组的价值为最大值减去最小值,每组至少有1个,如果这一组只有一个数的话,价值为0
问 最小的价值是多少
dp[i][j] 表示将 前 i 个数分成 j 组的最小价值
dp[i][j] = min(dp[k][j-1] + a[i]-a[k+1])
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int INF = (<<)-;
int n,m,a[];
LL dp[][]; void solve(){
for(int i = ;i <= n;i++)
for(int j = ;j <= m;j++) dp[i][j] = INF; sort(a+,a+n+);
for(int i = ;i <= n;i++){
dp[i][] = 1LL*(a[i]-a[]);
for(int j = ;j <= m;j++){
for(int k = ;k < i;k++){
dp[i][j] = min(dp[i][j],dp[k][j-]+1LL*(a[i]-a[k+]));
//printf("dp[%d][%d] = %d\n",i,j,dp[i][j]);
}
}
}
printf("%lld\n",dp[n][m]);
} int main(){
int T,kase = ;
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&m);
for(int i = ;i <= n;i++) scanf("%d",a+i);
printf("Case #%d: ",++kase);
solve();
}
return ;
}
最小生成树稍微变了下....可是卡了好久...好sb
将必须连接的k个最开始的祖先改成一样
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = ;
int n,m,k,a[],fa[],b[]; struct Edge{
int u,v,w,tag;
friend bool operator < (Edge a,Edge b){
return a.w < b.w;
}
}e[maxn*maxn]; int Find(int x){return x == fa[x] ? x :fa[x] = Find(fa[x]);} void solve(){
sort(e+,e+m+);
for(int i = ;i <= n;i++) fa[i] = i;
for(int i = ;i <= k;i++) fa[a[i]] = a[];
int tot = ,cc = n;
for(int i = ;i <= m;i++){
int u = e[i].u;
int v = e[i].v;
int x = Find(u);
int y = Find(v);
if(x != y){
fa[x] = y;
tot += e[i].w;
}
}
printf("%d\n",tot);
} int main(){
int T,kase = ;
scanf("%d",&T);
while(T--){
scanf("%d %d %d",&n,&m,&k);
memset(b,,sizeof(b));
for(int i = ;i <= k;i++) {
scanf("%d",a+i);
}
for(int i = ;i <= m;i++){
scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].w);
}
printf("Case #%d: ",++kase);
solve();
}
return ;
}
很多人过...可是就是想不出来
补题补题 2016.7.17
我好蠢啊..其实思路是差不多的,就觉得不对,没有去写
就是 碰到一样 的单词 就 ans += 2觉得有点不好写的是 怎么去比较这两个单词一不一样,因为终点不知道
原来 string 是 可以 从左边 加 的...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
string s; void solve(){
string l,r;
int len = s.length(),ans = ;
for(int i = ;*i < len;i++){
l += s[i];
if(i == len-i-) continue;
r = s[len-i-]+r;
//cout << l << " " << r << "\n";
if(l == r){
ans+= ;
l.clear();r.clear();
}
}
if(l.length() != || r.length() != ) ans++;
printf("%d\n",ans);
} int main(){
int T,kase = ;
scanf("%d",&T);
while(T--){
cin >> s;
printf("Case #%d: ",++kase);
solve();
}
return ;
}
UESTC 2016 Summer Training #6 Div.2的更多相关文章
- The Solution of UESTC 2016 Summer Training #1 Div.2 Problem C
Link http://acm.hust.edu.cn/vjudge/contest/121539#problem/C Description standard input/output After ...
- The Solution of UESTC 2016 Summer Training #1 Div.2 Problem B
Link http://acm.hust.edu.cn/vjudge/contest/121539#problem/B Description standard input/output Althou ...
- The Solution of UESTC 2016 Summer Training #1 Div.2 Problem A
Link http://acm.hust.edu.cn/vjudge/contest/121539#problem/A Description standard input/output Haneen ...
- UESTC 2016 Summer Training #1 Div.2
最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria ( ...
- UESTC 2016 Summer Training #1 J - Objects Panel (A) 按条件遍历树
#include <iostream> #include <cstdio> #include <vector> using namespace std; typed ...
- 2016 Multi-University Training Contests
2016 Multi-University Training Contest 1 2016 Multi-University Training Contest 2 2016 Multi-Univers ...
- 2016 Multi-University Training Contest 2 D. Differencia
Differencia Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 2016 Multi-University Training Contest 1 G. Rigid Frameworks
Rigid Frameworks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2016 Multi-University Training Contest 1
8/11 2016 Multi-University Training Contest 1 官方题解 老年选手历险记 最小生成树+线性期望 A Abandoned country(BH) 题意: 1. ...
随机推荐
- python_way day16 JQuary
python_way day16 JQuery 封装dom js代码 jQuery(1.10,1.12-兼容性好,2.0.以后放弃了ie9以下) - 封装了Dom & JavaScript 查 ...
- php 上传文件。$_FILES
<form name="article" method="post" enctype="multipart/form-data" ac ...
- iOS - Swift Closure 闭包
1.Closure 闭包在 Swift 中非常有用.通俗的解释就是一个 Int 类型里存储着一个整数,一个 String 类型包含着一串字符,同样,闭包是一个包含着函数的类型.有了闭包,你就可以处理很 ...
- iOS - UIColor
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIColor : NSObject <NSSecureCoding, NSCopying> @avai ...
- for循坏的穷举与迭代,while、do while循环
for循环的穷举:所有情况走一遍,使用if筛选出符合的情况. 单位发一张150元购物卡,到超市买三种洗化用品,洗发水15元,香皂两元,牙刷5元,刚好花完150元,有多少种买法,每种买法各买几样. 百鸡 ...
- python把元组组合成字典
list=((","16g"), (","32g"), (","red"), (","bl ...
- uva 11800 Determine the Shape
vjudge上题目链接:Determine the Shape 第二道独自 A 出的计算几何水题,题意就是给你四个点,让你判断它是哪种四边形:正方形.矩形.菱形.平行四边形.梯形 or 普通四边形. ...
- ID和Name的区别
HTML元素的ID和Name属性的区别一直认为ID和NAME是一样的,两个又可以一起出现,甚是疑惑.今天BAIDU了一下,才发现里面大有文章.发出来研究研究:最classical的答案:ID就像是一个 ...
- AngularJS的directive(指令)配置选项说明
js代码如下: var appModule = angular.module("appModule", []); appModule.controller("Ctrl&q ...
- ListView 搭配SimpleAdapter
这是SimplerAdapter的构造函数 public SimpleAdapter(Context context, List<? extends Map<String, ?>&g ...