我好菜啊..

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. 【BZOJ】4636: 蒟蒻的数列

    4636: 蒟蒻的数列 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 145  Solved: 71[Submit][Status][Discuss] ...

  2. Codeforces Round #272 (Div. 2) C. Dreamoon and Sums 数学

    C. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...

  3. 深入理解 C# 协变和逆变

    msdn 解释如下: “协变”是指能够使用与原始指定的派生类型相比,派生程度更大的类型. “逆变”则是指能够使用派生程度更小的类型. 解释的很正确,大致就是这样,不过不够直白. 直白的理解: “协变” ...

  4. DB2常识

    1.DB2组件 appendixa. db2 database product and packaging informatin一节AESE: 高级企业服务器版(Advanced enterprise ...

  5. iOS - OC Enum 枚举

    前言 iOS 5.0 之后,提供了新的枚举定义方式,定义枚举的同时,可以指定枚举中数据的类型. typedef NS_OPTIONS(_type, _name) new; -> 位移的,可以使用 ...

  6. poj3334Connected Gheeves(二分)

    链接 二分高度,算面积的地方有点麻烦,没有用求交点的模板,直接自己按三角形相似手算了一下,写的有点麻烦. 上下界直接取水可放的最高点以及最低点. 自己的长得很挫的代码 #include <ios ...

  7. hiho_1078_线段树区间修改

    题目 给定一组数,要求进行若干次操作,这些操作可以分为两种类型: (1) CMD 1 beg end value 将数组中下标在[beg, end] 区间内数字都变为value (2) CMD 2 b ...

  8. iOS开发 判断字符串是不是网址

    - (BOOL)isUrlString { NSString *emailRegex = @"[a-zA-z]+://.*"; NSPredicate *emailTest = [ ...

  9. linux 相关学习记录

    (一)概念① 物理CPU实际Server中插槽上的CPU个数物理cpu数量,可以数不重复的 physical id 有几个② 逻辑CPU /proc/cpuinfo 用来存储cpu硬件信息的信息内容分 ...

  10. VC++ 中使用 std::string 转换字符串编码

    目录 第1章说明    1 1.1 代码    1 1.2 使用    4 第1章说明 VC++中宽窄字符串的相互转换比较麻烦,借助std::string能大大减少代码量. 1.1 代码 函数声明如下 ...