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的更多相关文章

  1. TopCoder[SRM513 DIV 1]:Reflections(1000)

    Problem Statement      Manao is playing a new game called Reflections. The goal of the game is trans ...

  2. Topcoder SRM584 DIV 2 500

    #include <set> #include <iostream> #include <string> #include <vector> using ...

  3. Topcoder SRM583 DIV 2 250

    #include <string> #include <iostream> using namespace std; class SwappingDigits { public ...

  4. 【补解体报告】topcoder 634 DIV 2

    A:应该是道语文题,注意边界就好: B:开始考虑的太复杂,没能够完全提取题目的思维. 但还是A了!我愚蠢的做法:二分答案加暴力枚举, 枚举的时候是完全模拟的,比如每次取得时候都是从大到小的去取,最后统 ...

  5. Topcoder SRM548 Div 1

    1. KingdomAndTrees 给出n个数a[1..n],求一个数组b[1..n]满足b严格递增,且b[1]>=1. 定义代价为W = max{abs(a[i]-b[i])},求代价最小值 ...

  6. 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 ...

  7. TopCoder[SRM587 DIV 1]:ThreeColorability(900)

    Problem Statement      There is a H times W rectangle divided into unit cells. The rows of cells are ...

  8. TopCoder[SRM513 DIV 1]:PerfectMemory(500)

    Problem Statement      You might have played the game called Memoria. In this game, there is a board ...

  9. [topcoder]BinaryCards

    现在觉得有空时可以刷一下topcoder的DIV 2的Lvl 3的题目.感觉和刷LeetCode和WikiOi都是不一样的. http://community.topcoder.com/stat?c= ...

随机推荐

  1. How to move the user document folder to D disk[Windows 7]

    when you install windows 7 OS, the system ask for you enter username and password, then you have not ...

  2. 十天学会单片机Day2键盘检测(独立键盘、矩阵键盘)

    1.键盘的分类 编码键盘:键盘上闭合键的识别由专用的硬件编码器实现,并产生键编码号或键值的称为编码键盘,如计算机键盘 非编码键盘:靠软件编程来识别的称为非编码键盘.独立键盘.矩阵键盘 2.按键消抖   ...

  3. python中split与join

    1.split个人最喜欢的就是它能使输入的一连串数字变为list. str=raw_input("some ") str2=str.split(" ") str ...

  4. opensuse 安装 Anaconda3 之后出现Could not start d-bus. Can you call qdbus?

    最近在安装了opensue Leap42.1之后,想要学习一下python,就安装了Anaconda3,并且将Anaconda3的安装路径添加到了PATH里,但是在重新启动系统后,出现了"C ...

  5. [terry笔记]RMAN综合学习之恢复

    [terry笔记]RMAN综合学习之备份http://www.cnblogs.com/kkterry/p/3308405.html [terry笔记]RMAN综合学习之恢复 http://www.cn ...

  6. SQL基础篇---函数及其函数配套使用的关键字

    一.数值函数 知识点1 SUM 求总和 SELECT breakfast,sum(price) FROM my_foods GROUP BY breakfast ORDER BY SUM(price) ...

  7. 【转】C#中Invoke的用法

    在多线程编程中,我们经常要在工作线程中去更新界面显示,而在多线程中直接调用界面控件的方法是错误的做法,Invoke 和 BeginInvoke 就是为了解决这个问题而出现的,使你在多线程中安全的更新界 ...

  8. Python input()

    在Python语言中,我们经常需要与用户实现交互,下面是一个小实例 # -*- coding:UTF-8 -*- #获取输入参数,并将输入的值存储到txt文件中 String1 = input(&qu ...

  9. nginx 配置 ThinkPHP Rewrite

    server { listen 80; server_name www.funsion.com; root /www/web/funsion; index index.php; location / ...

  10. python中的多继承

    python和C++一样,支持多继承.概念虽然容易,但是困难的工作是如果子类调用一个自身没有定义的属性,它是按照何种顺序去到父类寻找呢,尤其是众多父类中有多个都包含该同名属性. class P1 #( ...