我好菜啊..

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. So easy Webservice 8.spring整合CXF 发布WS

    1.添加jar包(cxf的jar包中包含了spring的jar包),添加spring配置文件 2.web.xml中配置CXFServlet,过滤WS服务的地址 <!-- 配置CXFServlet ...

  2. WrapPanel流布局的一个简单例子

    <Window x:Class="WrapPanel.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2 ...

  3. 时间函数 time.h 详解

    C++对时间的操作也有许多值得大家注意的地方.最近,在技术群中有很多网友也多次问到过C++语言中对时间的操作.获取和显示等等的问题.下面,在这篇文章中,笔者将主要介绍在C/C++中时间和日期的使用方法 ...

  4. AS3 求两条直线的交点

    //粘贴到帧上运行即可 var p1Start:Point = new Point(0,0); var p1End:Point = new Point(50,50); var p2Start:Poin ...

  5. data-*属性——使用自定义属性的方式存储数据

    HTML5提供了data-*属性能存储页面或应用程序的私有自定义数据.只需在属性前加上data-前缀即可,值可以是任意字符串. 存储的(自定义)数据能够被页面的 JavaScript 中利用,以创建更 ...

  6. 关于C++类中的成员

    突然发现,如果C++的类成员中存在共有的成员,则可以通过指针的偏移来访问私有的成员变量,当然前提是对内存对齐比较清楚.只要骗过了编译器就可以为所欲为了. #include <cstdio> ...

  7. iOS - UISlider

    前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UISlider : UIControl <NSCoding> @a ...

  8. MySql 去重且指定某字段在前的排序方法

    今天遇到一个棘手的数据查找并去重的问题: 情况: 1.取出数据库中的数据: 2.同一字段A,不同情况<值,如A值为:a1,a2>下取出的其他数据可能相同: 3.将2情况下的重复数据< ...

  9. hostapd源代码分析(三):管理帧的收发和处理

    hostapd源代码分析(三):管理帧的收发和处理 原文链接:http://blog.csdn.net/qq_21949217/article/details/46004379 这篇文章我来讲解一下h ...

  10. [js] 有趣的js面试题,你答对了吗?

    题目1: 回答以下代码,alert的值分别是多少?