我好菜啊..

UVALive 6434

给出 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 ;
}

UVALive 6435

UVALive 6436

UVALive 6437

最小生成树稍微变了下....可是卡了好久...好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 ;
}

UVALive 6438

UVALive 6439

很多人过...可是就是想不出来

补题补题 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 ;
}

UVALive 6440

UVALive 6441

UVALive 6442

UVALive 6443

UESTC 2016 Summer Training #6 Div.2的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. UESTC 2016 Summer Training #1 Div.2

    最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria ( ...

  5. UESTC 2016 Summer Training #1 J - Objects Panel (A) 按条件遍历树

    #include <iostream> #include <cstdio> #include <vector> using namespace std; typed ...

  6. 2016 Multi-University Training Contests

    2016 Multi-University Training Contest 1 2016 Multi-University Training Contest 2 2016 Multi-Univers ...

  7. 2016 Multi-University Training Contest 2 D. Differencia

    Differencia Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  8. 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) ...

  9. 2016 Multi-University Training Contest 1

    8/11 2016 Multi-University Training Contest 1 官方题解 老年选手历险记 最小生成树+线性期望 A Abandoned country(BH) 题意: 1. ...

随机推荐

  1. clang: error: linker command failed with exit code 1 (use -v to see invocation)

    报错提示: ... ld: 6 duplicate symbols for architecture x86_64 clang: error: linker command failed with e ...

  2. HDU1518 Square(DFS)

    Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  3. FlexSlider插件的详细设置参数 http://www.woothemes.com/flexslider/ -----幻灯片插件

    $(window).load(function() { $('.flexslider').flexslider({ namespace: 'flex-', //控件的命名空间,会影响样式前缀 anim ...

  4. Java垃圾回收算法和垃圾回收器

    基本上 jvm内存回收有三种 基本算法 标记-清除 标记清除的算法最简单,主要是标记出来需要回收的对象,然后然后把这些对象在内存的信息清除.如何标记需要回收的对象,在上一篇文章里面已经有说明. 标记- ...

  5. Spring的DI(Ioc) - 注入集合类型

    1: 首先给service添加集合类型的属性,并提供getter, setter package cn.gbx.serviceimpl; import java.util.ArrayList; imp ...

  6. spring的下载地址(转)

    http://hi.baidu.com/jaimy_jie/item/d699cecdc5d3a354bdef6990 SPRING官方网站改版后,建议都是通过 Maven和Gradle下载,对不使用 ...

  7. 差之毫厘谬之千里!带你认识CPU后缀含义

    intel的几代CPU中,后缀字母主要有以下几种: M:笔记本专用CPU,一般为双核,M前面一位数字是0,意味着是标准电压处理器,如果是7,则是低电压处理器. U:笔记本专用低电压CPU,一般为双核, ...

  8. TortoiseSVN文档

    https://tortoisesvn.net/docs/release/TortoiseSVN_zh_CN/index.html TortoiseSVN 针对 Windows 平台的 Subvers ...

  9. 如何使div左右倾斜

    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" ...

  10. easyui中对于dialog页面传值的接收

    dialog的功能是将B页面嵌入至A页面,这样,A页面作为B页面的父容器,所有的元素均可以被B页面访问 那么问题来了:我怎么获取B页面的链接参数呢? 其实很简单,只要找到B页面的存放容器即可: 代码如 ...