#include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #define N 70 int f, vis[N], v, n, a[N]; int cmp(const void *a, const void *b) { return *(int *)b - *(int *)a; } void DFS(int w, int sum) { int i; ) f = ; else…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4911 解题报告: 给出一个长度为n的序列,然后给出一个k,要你求最多做k次相邻的数字交换后,逆序数最少是多少? 因为每次相邻的交换操作最多只能减少一个逆序对,所以最多可以减少k个逆序对,所以我们只要求出原来的序列有多少个逆序对然后减去k再跟0取较大的就可以了. 因为数据范围是10的五次方,所以暴力求肯定会TLE,所以要用n*logn算法求逆序对,n*logn算法有几种可以求逆序对的: 线段树,树状数…
http://acm.hdu.edu.cn/showproblem.php?pid=1711 #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> ], b[], next[]; int n, m; void GetNext(int b[])//获得next数组 { , j = ; next[] = -; while(j < m) { || b[j] == b[…
http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意: 一个字符串,有多少个subsequence是回文串. 别人的题解: 用dp[i][j]表示这一段里有多少个回文串,那首先dp[i][j]=dp[i+1][j]+dp[i][j-1],但是dp[i+1][j]和dp[i][j-1]可能有公共部分,所以要减去dp[i+1][j-1]. 如果str[i]==str[j]的话,还要加上dp[i+1][j-1]+1. 但是自己却是这样想的,把每个区间都要看…
http://acm.hdu.edu.cn/showproblem.php?pid=6602 终于能够看懂的题解: https://blog.csdn.net/qq_40871466/article/details/97189033 依次枚举r,对r寻找可行的最小的l,查找成功则尝试更新. 假如每次把合法区间+1,把非法区间-1,那么对一段区间求区间和表示什么呢? k=2 1 4 1 4 2 1 2 r=1,均为非法区间 -1 0 0 0 0 0 0 r=2,均为非法区间 -2 -1 0 0 0…
Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.   Input 输入若干组数据.每组数据包括:导弹总个数(正…
#include<stdio.h> #include<string.h> #include<queue> #define N 110 int m, n, k, x1, x2, y1, y2; char map[N][N]; int v[N][N][N];//当时间是k的倍数时,障碍消失,之后又重现,所以在平时使用的二维标记数组中再加一维 ][] = {{-, }, {, }, {, -}, {, }}; using namespace std; struct node…
riemann与marjorie拼接后riemannmarjorie前缀与后缀公共部分为 rie 长度为 3(即next[l] = next[14]的值,l为拼接后的长度)但:aaaa与aa拼接后aaaaaa,next[l]不是结果,所以在aaaa和aa间加“#”,即aaaa#aa:#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #define N 50010…
//代码: //方法1:Dijkstra's Algorithm #include<stdio.h> #include<math.h> #include<string.h> #define INF 0xfffffff #define N 110 #define min(a, b)(a < b ? a : b) int maps[N][N]; int d[N], visit[N]; int n, m; void Init() { int i, j; memset(v…
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<queue> #include<math.h> #define N 10010 using namespace std; int vis[N]; ], s2[], s3[]; struct node { int step; ]; }; int prime(int y) { int i, k = (int)sqrt(y)…