Topcoder Srm627 DIV 2
A,B:很水,注意边界,话说HACK都是这些原因。
C:
R[I][J]:表示反转I-J能改变冒泡排序的次数;
DP方程:dp[i][k]=max(dp[j][k],dp[j][k-1]+dp[j][i]) (0<=j<i)
最后枚举,具体看代码
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string.h> using namespace std;
class BubbleSortWithReversals{
public:
int bs(vector<int> a)
{
int n=a.size(),ans=0; while (n--){
for (int i=0;i<a.size()-1;i++)
if (a[i]>a[i+1])
{
swap(a[i],a[i+1]);
ans++;
}
}
return ans;
} int getMinSwaps(vector<int> A,int K){
int n=A.size();
int dp[55][55]={0};
int r[55][55]={0}; for (int i=0;i<n;i++)
for (int j=i+1;j<n;j++){
r[i][j]=bs(A);
reverse(A.begin()+i,A.begin()+j+1);
r[i][j]-=bs(A);
reverse(A.begin()+i,A.begin()+j+1);
} for (int i=0;i<n;i++){
for (int k=1;k<=K;k++)
for (int j=0;j<i;j++)
{
dp[i][k]=max(dp[i][k],dp[j][k]);
dp[i][k]=max(dp[i][k],dp[j][k-1]+r[j][i]);
}
} int ans=0;
for (int i=0;i<=K;i++)
ans=max(ans,dp[n-1][i]);
return bs(A)-ans;
}
};
Topcoder Srm627 DIV 2的更多相关文章
- TopCoder[SRM513 DIV 1]:Reflections(1000)
Problem Statement Manao is playing a new game called Reflections. The goal of the game is trans ...
- Topcoder SRM584 DIV 2 500
#include <set> #include <iostream> #include <string> #include <vector> using ...
- Topcoder SRM583 DIV 2 250
#include <string> #include <iostream> using namespace std; class SwappingDigits { public ...
- 【补解体报告】topcoder 634 DIV 2
A:应该是道语文题,注意边界就好: B:开始考虑的太复杂,没能够完全提取题目的思维. 但还是A了!我愚蠢的做法:二分答案加暴力枚举, 枚举的时候是完全模拟的,比如每次取得时候都是从大到小的去取,最后统 ...
- Topcoder SRM548 Div 1
1. KingdomAndTrees 给出n个数a[1..n],求一个数组b[1..n]满足b严格递增,且b[1]>=1. 定义代价为W = max{abs(a[i]-b[i])},求代价最小值 ...
- TopCoder[SRM587 DIV 1]:TriangleXor(550)
Problem Statement You are given an int W. There is a rectangle in the XY-plane with corners at ...
- TopCoder[SRM587 DIV 1]:ThreeColorability(900)
Problem Statement There is a H times W rectangle divided into unit cells. The rows of cells are ...
- TopCoder[SRM513 DIV 1]:PerfectMemory(500)
Problem Statement You might have played the game called Memoria. In this game, there is a board ...
- [topcoder]BinaryCards
现在觉得有空时可以刷一下topcoder的DIV 2的Lvl 3的题目.感觉和刷LeetCode和WikiOi都是不一样的. http://community.topcoder.com/stat?c= ...
随机推荐
- c#写入Mysql中文显示乱码 解决方法
如题,mysql字符集utf8,c#写入中文后,全部显示成?,一个汉字对应一个?解决方法:在数据库连接字符串中增加字符集的说明,Charset=utf8,如 MySQLConnection con = ...
- 8.css边框
其实,与其将css盒模型称为是一个盒子,我更愿意将其称为卡片,或者是图画.因为相对于盒子的三维特效,网页的元素更像是二维的图画.而我们之间对元素尺寸之类的调整,更像是对画布的调整. 但是,就像我可以为 ...
- AppCan4.0:开发者要做有价值的APP
在当今的移动盛世,谈论APP“生存”话题未免太过沉重.但面对百万级移动应用大军所产生的激烈竞争,且保证“立而不倒”,这样的探讨就显得格外重要了. 主打“价值牌”才能“一条龙” 有这样一组数据,在我国, ...
- SaaS应用“正益工作”发布,为大中型企业轻松构建移动门户
6月24日,以“平台之上,应用无限”为主题的2016 AppCan移动开发者大会,在北京国际会议中心隆重举行,逾1500名移动开发者一起见证了此次大会盛况. 会上,在专家领导.技术大咖.移动开发者的共 ...
- hdu 5281 Senior's Gun
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5281 Senior's Gun Description Xuejiejie is a beautifu ...
- android开发系列之代码整洁之道
说起代码整洁之道,想必大家想到更多的是那本经典重构书籍.没错,记得当时自己读那本书的时候,一边结合项目实战,一边结合书中的讲解,确实学到了很多东西,对我自己的编码风格影响极深.随着时间的流逝,书中很多 ...
- WIndows7 多版本
Windows7 安装U盘 删除source\ei.cfg 以后开机安装会提示安装的版本
- qu
离骚 (3481人评分) 8.5 朝代:先秦 作者:屈原 原文: 帝高阳之苗裔兮,朕皇考曰伯庸.摄提贞于孟陬兮,惟庚寅吾以降.皇览揆余初度兮,肇锡余以嘉名:名余曰正则兮,字余曰灵均.纷吾既有此内美 ...
- iOS之push present 动画
直接源码: - (void) transitionWithType:(NSString *) type WithSubtype:(NSString *) subtype ForView : (UIVi ...
- php webservice soap
http://www.cnblogs.com/phpdragon/archive/2012/06/10/2544171.html http://jeffxie.blog.51cto.com/13653 ...