UESTC 2016 Summer Training #6 Div.2
我好菜啊..
给出 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 ;
- }
最小生成树稍微变了下....可是卡了好久...好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 ;
- }
很多人过...可是就是想不出来
补题补题 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 ;
- }
UESTC 2016 Summer Training #6 Div.2的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- UESTC 2016 Summer Training #1 Div.2
最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria ( ...
- UESTC 2016 Summer Training #1 J - Objects Panel (A) 按条件遍历树
#include <iostream> #include <cstdio> #include <vector> using namespace std; typed ...
- 2016 Multi-University Training Contests
2016 Multi-University Training Contest 1 2016 Multi-University Training Contest 2 2016 Multi-Univers ...
- 2016 Multi-University Training Contest 2 D. Differencia
Differencia Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 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) ...
- 2016 Multi-University Training Contest 1
8/11 2016 Multi-University Training Contest 1 官方题解 老年选手历险记 最小生成树+线性期望 A Abandoned country(BH) 题意: 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 ...
- codevs 1294 全排列 next_permuntation
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #de ...
- UVA 11468【AC自动机+DP】
dp[i][j]表示走了i步走到j结点的概率.初始值dp[0][0] = 1.当走到的结点不是单词尾结点时,才能走过去. !end[i]&&last[i] == root时,该结点才可 ...
- hdu5406 CRB and Apple dp+两个LIS
题意转换为:给定n个数,求两个最长的不相交的LIS. 先说经典题一个LIS的nlogn做法.枚举当前数,若比末尾数大,插入末尾,否则二分查找,插入合适位置. 通过此题,我们有了一个用树状数组或线段树+ ...
- 【转载】高性能IO设计 & Java NIO & 同步/异步 阻塞/非阻塞 Reactor/Proactor
开始准备看Java NIO的,这篇文章:http://xly1981.iteye.com/blog/1735862 里面提到了这篇文章 http://xmuzyq.iteye.com/blog/783 ...
- ajax跨域jsonp
<!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...
- C++常量(C++数值常量、字符串常量、符号常量)
http://see.xidian.edu.cn/cpp/biancheng/view/104.html 字符串常量 用双撇号括起来的部分就是字符串常量,如"abc"," ...
- hiho1123_好配对
题目 给定两个序列a和b,每个序列中可能含有重复的数字. 一个配对(i,j)是一个好配对当从第一个序列中选出一个数ai,再从第二个序列中选出一个数bj且满足ai>bj. 给出两个序列,问存在多少 ...
- iOS开发 字符串添加行间距
+ (CGFloat)achiveWidthAttrString:(NSAttributedString *)attrString withHeight:(CGFloat)height { CGRec ...
- smarty 快速上手
smarty半小时快速上手入门教程 投稿:shichen2014 字体:[增加 减小] 类型:转载 时间:2014-10-27我要评论 这篇文章主要介绍了smarty半小时快速上手入门教程,以实例的形 ...