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= ...
随机推荐
- STM32F0_新建软件工程详细过程
前言 由于ST公司推出比STM32F1性价比更高的F0芯片,现在市面上F0芯片的占有率也非常高.F0芯片属于M0内核,主频48M(当然,可以超频的,但尽量不要超的太多),资源大小可根据项目需求来选型. ...
- linux的串口驱动分析
1.串口驱动中的数据结构 • UART驱动程序结构:struct uart_driver 驱动 • UART端口结构: struct uart_port 串口 • UART相关操作函数结构: st ...
- 实战Django:官方实例Part1
[写在前面] 撰写这个实战系列的Django文章,是很久之前就有的想法,问题是手头实例太少,一旦开讲,恐有"无米下锅"之忧. 随着对Django学习的深入,渐渐有了些心得,把这些心 ...
- m3u8
audo apt-get install pkg-configsudo apt-get install automake autoconf m4 libtool sudo apt-get instal ...
- hdu 3371 Connect the Cities
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3371 Connect the Cities Description In 2100, since th ...
- 贵州大学iPhone、Android(安卓)项目助跑计划!!!
该计划旨在帮助同学们将各种脑中稀奇古怪的想法借助互联网/移动互联网相关的技术变成真实的项目. 谱写你的故事,从此刻开始! 我们帮助你提高编程(Java.C++.Objective-C.Android. ...
- sychronized面试问题浅析
先说下面试吧,整体来说基础准备好点,简历别太假,然后回答起来实事求是,表现自然的点基本上都没问题吧(针对初级职位,记得有个hr说过对于新人基础扎实和为人真诚是最关键的),两天时间跑起来挺累,反而觉得面 ...
- 数组链表下标指针map list
1.时间复杂度 (1)时间频度 一个算法执行所耗费的时间,从理论上是不能算出来的,必须上机运行测试才能知道.但我们不可能也没有必要对每个算法都上机测试,只需知道哪个算法花费的时间多,哪个算法花费的时间 ...
- 初识java之Mina(一)
Apache Mina Server 是一个网络通信应用框架,也就是说,它主要是对基于 TCP/IP.UDP/IP协议栈的通信框架(当然,也可以提供 JAVA 对象的序列化服务.虚拟机管道通信服务等) ...
- C#的winform矩阵简单运算
C#的winform矩阵简单运算 程序截图 关键代码 using System; using System.Collections.Generic; using System.ComponentMod ...