我好菜啊..

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. python_way day17 jQuery表单验证,事件绑定,插件,文本框架,正则表达式

    python_way day17 1.jQuery表单验证 dom事件绑定 jquery事件绑定 $.each return值的判断 jquery扩展方法 2.前段插件 3.jDango文本框架 4. ...

  2. 在ubuntu上配置apue的运行环境

    http://www.apuebook.com/code3e.html 在上面的网站下载代码包,解压得到源码 sudo apt-get install libbsd-dev 安装这个支持,在解压包的m ...

  3. NS_ASSUME_NONNULL_BEGIN,NS_ASSUME_NONNULL_END

    Nonnull区域设置(Audited Regions) 如果需要每个属性或每个方法都去指定nonnull和nullable,是一件非常繁琐的事.苹果为了减轻我们的工作量,专门提供了两个宏:NS_AS ...

  4. linux虚拟机安装

    1.真实机第一次安装必须先搞f2进入boot从光盘启动,虚拟机不用 进入的时候五个选项Install or upgrade an existing system:安装或升级现有系统Install sy ...

  5. jquery+ajax(用ajax.dll)实现无刷新分页

    利用ajax.dll那种方式的无刷新,在这就不说了,新朋友可以看下我的另一片文件http://www.cnblogs.com/dachuang/p/3654632.html 首先,这里用的是jquer ...

  6. Python学习(12)日期和时间

    目录 Python 日期和时间 时间元组 获取当前时间 获取格式化时间 格式化日历 获取某月日历 Time模块 日历模块 其他相关模块和函数 Python 日期和时间 Python 程序能用很多方式处 ...

  7. Java源码初学_HashSet&LinkedHashSet

    一.概述 HashSet是建立在HashMap的基础上的,其内部存在指向一个HashMap对象的引用,操作HashSet实际上就是操作HashMap,而HashMap中所有键的值都指向一个叫做Dumm ...

  8. jQuery UI 实例 - 对话框(Dialog)(zhuan)

    http://www.runoob.com/jqueryui/example-dialog.html ************************************************* ...

  9. HashMap循环遍历方式及其性能对比(zhuan)

    http://www.trinea.cn/android/hashmap-loop-performance/ ********************************************* ...

  10. PHP_解析xss攻击、sql注入

    /** * PHP解决XSS(跨站脚本攻击)的调用函数 * PHP跨站脚本漏洞补丁,去除XSS(跨站脚本攻击)的函数,把以下代码保存在function.php文件中,在需要防御的页面中include ...