我好菜啊..

UVALive 6434

给出 n 个数,分成m组,每组的价值为最大值减去最小值,每组至少有1个,如果这一组只有一个数的话,价值为0

问 最小的价值是多少

dp[i][j] 表示将 前 i 个数分成 j 组的最小价值

dp[i][j] = min(dp[k][j-1] + a[i]-a[k+1])

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6. typedef long long LL;
  7. const int INF = (<<)-;
  8. int n,m,a[];
  9. LL dp[][];
  10.  
  11. void solve(){
  12. for(int i = ;i <= n;i++)
  13. for(int j = ;j <= m;j++) dp[i][j] = INF;
  14.  
  15. sort(a+,a+n+);
  16. for(int i = ;i <= n;i++){
  17. dp[i][] = 1LL*(a[i]-a[]);
  18. for(int j = ;j <= m;j++){
  19. for(int k = ;k < i;k++){
  20. dp[i][j] = min(dp[i][j],dp[k][j-]+1LL*(a[i]-a[k+]));
  21. //printf("dp[%d][%d] = %d\n",i,j,dp[i][j]);
  22. }
  23. }
  24. }
  25. printf("%lld\n",dp[n][m]);
  26. }
  27.  
  28. int main(){
  29. int T,kase = ;
  30. scanf("%d",&T);
  31. while(T--){
  32. scanf("%d %d",&n,&m);
  33. for(int i = ;i <= n;i++) scanf("%d",a+i);
  34. printf("Case #%d: ",++kase);
  35. solve();
  36. }
  37. return ;
  38. }

UVALive 6435

UVALive 6436

UVALive 6437

最小生成树稍微变了下....可是卡了好久...好sb

将必须连接的k个最开始的祖先改成一样

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6. const int maxn = ;
  7. int n,m,k,a[],fa[],b[];
  8.  
  9. struct Edge{
  10. int u,v,w,tag;
  11. friend bool operator < (Edge a,Edge b){
  12. return a.w < b.w;
  13. }
  14. }e[maxn*maxn];
  15.  
  16. int Find(int x){return x == fa[x] ? x :fa[x] = Find(fa[x]);}
  17.  
  18. void solve(){
  19. sort(e+,e+m+);
  20. for(int i = ;i <= n;i++) fa[i] = i;
  21. for(int i = ;i <= k;i++) fa[a[i]] = a[];
  22. int tot = ,cc = n;
  23. for(int i = ;i <= m;i++){
  24. int u = e[i].u;
  25. int v = e[i].v;
  26. int x = Find(u);
  27. int y = Find(v);
  28. if(x != y){
  29. fa[x] = y;
  30. tot += e[i].w;
  31. }
  32. }
  33. printf("%d\n",tot);
  34. }
  35.  
  36. int main(){
  37. int T,kase = ;
  38. scanf("%d",&T);
  39. while(T--){
  40. scanf("%d %d %d",&n,&m,&k);
  41. memset(b,,sizeof(b));
  42. for(int i = ;i <= k;i++) {
  43. scanf("%d",a+i);
  44. }
  45. for(int i = ;i <= m;i++){
  46. scanf("%d %d %d",&e[i].u,&e[i].v,&e[i].w);
  47. }
  48. printf("Case #%d: ",++kase);
  49. solve();
  50. }
  51. return ;
  52. }

UVALive 6438

UVALive 6439

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

补题补题 2016.7.17

我好蠢啊..其实思路是差不多的,就觉得不对,没有去写

就是 碰到一样 的单词 就 ans += 2觉得有点不好写的是 怎么去比较这两个单词一不一样,因为终点不知道

原来 string 是 可以 从左边 加 的...

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6. string s;
  7.  
  8. void solve(){
  9. string l,r;
  10. int len = s.length(),ans = ;
  11. for(int i = ;*i < len;i++){
  12. l += s[i];
  13. if(i == len-i-) continue;
  14. r = s[len-i-]+r;
  15. //cout << l << " " << r << "\n";
  16. if(l == r){
  17. ans+= ;
  18. l.clear();r.clear();
  19. }
  20. }
  21. if(l.length() != || r.length() != ) ans++;
  22. printf("%d\n",ans);
  23. }
  24.  
  25. int main(){
  26. int T,kase = ;
  27. scanf("%d",&T);
  28. while(T--){
  29. cin >> s;
  30. printf("Case #%d: ",++kase);
  31. solve();
  32. }
  33. return ;
  34. }

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. Codeforces Round #135 (Div. 2) E. Parking Lot 线段数区间合并

    E. Parking Lot time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  2. codevs 1294 全排列 next_permuntation

    #include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #de ...

  3. UVA 11468【AC自动机+DP】

    dp[i][j]表示走了i步走到j结点的概率.初始值dp[0][0] = 1.当走到的结点不是单词尾结点时,才能走过去. !end[i]&&last[i] == root时,该结点才可 ...

  4. hdu5406 CRB and Apple dp+两个LIS

    题意转换为:给定n个数,求两个最长的不相交的LIS. 先说经典题一个LIS的nlogn做法.枚举当前数,若比末尾数大,插入末尾,否则二分查找,插入合适位置. 通过此题,我们有了一个用树状数组或线段树+ ...

  5. 【转载】高性能IO设计 & Java NIO & 同步/异步 阻塞/非阻塞 Reactor/Proactor

    开始准备看Java NIO的,这篇文章:http://xly1981.iteye.com/blog/1735862 里面提到了这篇文章 http://xmuzyq.iteye.com/blog/783 ...

  6. ajax跨域jsonp

    <!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...

  7. C++常量(C++数值常量、字符串常量、符号常量)

    http://see.xidian.edu.cn/cpp/biancheng/view/104.html 字符串常量 用双撇号括起来的部分就是字符串常量,如"abc"," ...

  8. hiho1123_好配对

    题目 给定两个序列a和b,每个序列中可能含有重复的数字. 一个配对(i,j)是一个好配对当从第一个序列中选出一个数ai,再从第二个序列中选出一个数bj且满足ai>bj. 给出两个序列,问存在多少 ...

  9. iOS开发 字符串添加行间距

    + (CGFloat)achiveWidthAttrString:(NSAttributedString *)attrString withHeight:(CGFloat)height { CGRec ...

  10. smarty 快速上手

    smarty半小时快速上手入门教程 投稿:shichen2014 字体:[增加 减小] 类型:转载 时间:2014-10-27我要评论 这篇文章主要介绍了smarty半小时快速上手入门教程,以实例的形 ...