上一页 1 ··· 53 54 55 56 57 58 59 60 61 ··· 182 下一页
摘要: 题意:要求用两两交换的方式给一个数列排序,交换f[i]和f[j]的代价为f[i]+f[j],求最小代价。分析:具体方法就是在数列中找置换环,每个环有两种处理方式,一种是用最小的元素将环里所有元素归位,另一种是用全数列最小元素与环内最小元素交换,并在环内用这个全数列最小元素将环里所有元素归位,再与原环内最小元素交换回来。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using na 阅读全文
posted @ 2012-07-06 13:27 undefined2024 阅读(784) 评论(0) 推荐(0)
摘要: dp,f[i][j][k]表示用i个不同的素数相加等于k的方法数,且这i个素数只能在前j个数字中选。f[i][j][k] = f[i][j - 1][k] + f[i - 1][j - 1][k - w[j]];(w[j]为第j个素数的值)View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;#define maxn 1200#define maxr 20 阅读全文
posted @ 2012-07-06 10:44 undefined2024 阅读(188) 评论(0) 推荐(0)
摘要: 最大独立集,把不认识的男女看成是有矛盾的,要选出一些互相没有矛盾的男女。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 205bool g[maxn][maxn];int uN, vN, m;int xM[maxn], yM[maxn];bool chk[maxn];void input(){ for (int i = 0; i < m; i++) { int 阅读全文
posted @ 2012-07-06 09:23 undefined2024 阅读(129) 评论(0) 推荐(0)
摘要: 简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 2008int n;char line[maxn];void input(){ scanf("%d", &n); for (int i = 0; i < n; i++) { char ch[3]; scanf("%s", ch); line[i] = ch[0] 阅读全文
posted @ 2012-07-06 09:06 undefined2024 阅读(503) 评论(0) 推荐(0)
摘要: 最小路径覆盖,把每个ride看成一个点,如果两个ride可以先后由一辆车完成,那么就从前一个ride引一条边到后一个ride。在最小路经覆盖中,原图的邻接矩阵和二分图匹配的邻接矩阵为同一矩阵View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;#define maxn 505struct Elem{ int x1, y1, x2, y2; int s, e 阅读全文
posted @ 2012-07-05 19:37 undefined2024 阅读(279) 评论(0) 推荐(0)
上一页 1 ··· 53 54 55 56 57 58 59 60 61 ··· 182 下一页