摘要:
题意:求对字符串最少添加几个字符可变为回文串。分析:简单做法是直接对它和它的逆序串求最长公共子序列长度len。n-len即为所求。(n为原串长度)这样做的原因如下:要求最少添加几个字符,我们可以先从原串中找到一个最长回文串,然后对于原串中不属于这个回文串的字符,在它关于回文串中心的对称位置添加一个相同字符即可。那么需要添加的字符数量即为n-最长回文串长度。最长回文串可以看作是原串中前面和后面字符的一种匹配(每个后面的字符在前面找到一个符合位置要求的与它相同的字符)。这种的回文匹配和原串与逆序串的公共子序列是一一对应的(一个回文匹配对应一个公共子序列,反之亦然),而且两者所涉及到的原串中的字符数 阅读全文
posted @ 2011-06-24 20:28
undefined2024
阅读(1039)
评论(0)
推荐(0)
摘要:
简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 105int n, m;int v[maxn][maxn], f[maxn][maxn];int main(){ //freopen("t.txt", "r", stdin); scanf("%d%d", &n, &m); for (int 阅读全文
posted @ 2011-06-24 19:40
undefined2024
阅读(154)
评论(0)
推荐(0)
摘要:
题意:给出平面上若干个点的坐标,让建一个环形围墙,把所有的点围在里面,且距所有点的距离不小于l。求围墙的最小长度。分析:凸包周长+半径为l的圆周长View Code #include #include #include #include #include #include usingnamespace std;#define maxn 1005struct point{ double x, y;} pnt[maxn], res[maxn];int n, l;bool mult(point sp, point ep, point op){ return (sp.x - op.x) *... 阅读全文
posted @ 2011-06-24 17:14
undefined2024
阅读(1233)
评论(0)
推荐(0)
摘要:
简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define inf 0x3f3f3f3f#define maxn 105int vis[maxn];int lowc[maxn];int cost[maxn][maxn];int n;void input(){ for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) s 阅读全文
posted @ 2011-06-24 16:46
undefined2024
阅读(499)
评论(0)
推荐(0)
摘要:
简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;char st[20];int num[20];int n;int len;char ans[20];bool cmp(const char &a, const char &b){ int x = a - 'A'; int y = b - 'A 阅读全文
posted @ 2011-06-24 16:30
undefined2024
阅读(375)
评论(0)
推荐(0)