- 博客(25)
- 收藏
- 关注
原创 POJ3280(动态规划)
最近寒假回家很无聊,荒废了一个星期的算法,有点罪恶 题目意思很简单,类似的题目碰到过一些,动态规划解决,dp[i][j]表示从i开始到j结束的串行成回文的最小代价,递推方程如下:D[s]为删除s的代价,A[s]为添加s的代价。假设字符串为S1..Si..Sj...Smmin中的五项分别对应于以下几种情况, Case1:
2014-01-13 14:06:58 736
原创 POJ2593
#include "stdio.h"#define MAXN 100000int a[ MAXN ];int lmax[ MAXN ];int rmax[ MAXN ];int ldp[ MAXN ];int rdp[ MAXN ];int N;void init(){ ldp[ 0 ] = a[ 0 ]; lmax[ 0 ] = ldp[ 0 ]; for(i
2013-09-21 10:24:59 655
原创 POJ2479
#include "stdio.h"#define MAXN 50000int a[ MAXN ];int lmax[ MAXN ];int rmax[ MAXN ];int ldp[ MAXN ];int rdp[ MAXN ];int n;void init(){ ldp[ 0 ] = a[ 0 ]; lmax[ 0 ] = ldp[ 0 ]; for(in
2013-09-21 10:17:58 521
原创 POJ1836(LIS)
#include "stdio.h"#define MAXN 1000double h[ MAXN ];int left[ MAXN ];int right[ MAXN ];int N;void init(){ int i, j; for(i = 0; i < N; i ++) { for(j = 0; j < i; j ++) { if(h[ i ] >
2013-09-20 22:01:28 571
原创 杭电ACM1325(并查集)
#include using namespace std;#define MAXN 100001int father[ MAXN ];int visited[ MAXN ];int in[ MAXN ];int out[ MAXN ];bool flag;void init(){ for(int i = 0; i < MAXN; i ++) { father[ i
2013-09-05 22:07:54 533
原创 杭电ACM1272(并查集)
#include using namespace std;#define MAXN 100001int father[ MAXN ];int visited[ MAXN ];bool flag;void init(){ for(int i = 0; i < MAXN; i ++) { father[ i ] = i; visited[ i ] = 0; } fl
2013-09-04 22:56:58 531
原创 杭电ACM4006(最小堆)
#include using namespace std;int Heap[ 1000002 ]; //最小堆 int size;void siftDown(int s){ int minOne = 2 * s; while(minOne <= size) { if(minOne + 1 Heap[ minOne + 1 ]) { minOne ++;
2013-08-28 13:42:17 600
原创 杭电ACM1005(矩阵乘法)
#include using namespace std;int matrix[ 2 ][ 2 ];int tMatrix[ 2 ][ 2 ];int res[ 2 ][ 2 ];int A, B, n;void calc(){ while(n != 0) { if(n & 1 == 1) { tMatrix[ 0 ][ 0 ] = matrix[ 0 ][
2013-08-24 15:15:47 697
原创 杭电ACM1083(二分图匹配)
#include using namespace std;int Map[ 305 ][ 305 ];int link[ 305 ];int visit[ 305 ];int P, N;void init(){ for(int i = 0; i < P; i ++) { for(int j = 0; j < N; j ++) { Map[ i ][ j ] =
2013-08-19 16:06:27 523
原创 杭电ACM1203(贪心法)
#include #include #include using namespace std;struct node{ int a; double b;};vector ns;bool cmp(node n1, node n2){ return n1.b > n2.b;}int main(){ int n, m; while(
2013-08-15 20:49:54 515
原创 杭电ACM1203(动态规划)
#include using namespace std;#define MAXN 10002double v[ MAXN ];int main(){ int n, m; int a; double b; while(cin>>n>>m) { if(n == 0 && m ==0) { break; } for(int i = 0; i <= n;
2013-08-15 20:48:47 635
原创 杭电ACM1241(搜索题)
#include using namespace std;#define MAXN 102char Map[ MAXN ][ MAXN ];int m, n;void search(int i, int j){ Map[ i ][ j ] = '*'; if(Map[ i + 1 ][ j ] == '@') { search(i + 1,
2013-08-13 10:08:12 551
原创 杭电ACM1010(搜索题)
#include using namespace std;char Maze[ 9 ][ 9 ];struct pos{ int x, y;};int flag;int access;void fun(pos src, pos dst, int time){ if(src.x == dst.x && src.y == dst.y && time == 0)//成功
2013-08-12 23:02:24 619
原创 杭电ACM1239(搜索题)
#include #include #include using namespace std;vector primes;int m, a, b, p, q;int main(){ primes.push_back(2); for(int i = 3; i <= 10000; i ++) { int max = sqrt((double)i) + 1; int c
2013-08-12 21:36:43 411
原创 杭电ACM1238(搜索题)
#include #include #include #include using namespace std;#define MAXN 100vector strs;int n;bool find(string sub){ for(int i = 0; i < n; i ++) { if(string::npos == strs[ i ].find(sub))
2013-08-12 21:07:41 531
原创 杭电ACM1068(二分图)
#include using namespace std;#define MAXN 1005int match[ MAXN ][ MAXN ];int link[ MAXN ];int visit[ MAXN ];int n;void init(){ for(int i = 0; i < n; i ++) { for(int j = 0; j
2013-08-09 20:09:17 501
原创 杭电ACM2063(二分图匹配)
#include using namespace std;#define MAXN 500int match[ MAXN ][ MAXN ];int visit[ MAXN ];int link[ MAXN ];int K, M, N, A, B;void init(){ for(int i = 0; i < N; i ++) { for(int j = 0; j <
2013-08-07 12:38:13 700
原创 杭电ACM1425(排序)
#include using namespace std;int n, m;int partion(int* array, int low, int high){ int index = low; int pivot = array[ index ]; swap(array[ index ], array[ high ]); for(int i = low; i < hig
2013-08-06 21:38:59 934
原创 杭电ACM1863(最小生成树)
#include using namespace std;#define MAXN 100#define INF 100000int cost[ MAXN ][ MAXN ];int lowcost[ MAXN ];int M, N, A, B, C;void init(){ for(int i = 0; i < M; i ++) {
2013-08-06 20:56:20 702
原创 杭电ACM1532(最大流)
#include #include using namespace std;#define MAXN 200#define MAXC 10000000int f[ MAXN ][ MAXN ];int previous[ MAXN ];queue q;int N, M, S, E, C;void init(){ for(int i = 0; i < MAXN; i ++
2013-08-06 17:33:50 498
原创 杭电ACM3549(最大流)
#include #include using namespace std;#define MAXN 15#define MAXC 1005int f[ MAXN ][ MAXN ];queue q;int previous[ MAXN ];int T, N, M, X, Y, C;void init(){ for(int i = 0; i < N; i ++) {
2013-08-06 16:34:41 503
原创 杭电ACM2544(最短路径)
#include using namespace std;#define MAXN 100#define INF 100005int dis[ MAXN ][ MAXN ];int N, M, A, B, C;void init(){ for(int i = 0; i < N; i ++) { for(int j = 0; j < N; j ++) { dis
2013-08-06 14:05:51 644
原创 杭电ACM1874(最短路径)
#include using namespace std;#define MAXN 200#define INF 10000int dis[ MAXN ][ MAXN ];int N, M, A, B, X, S, T;int dij(){ int *d = new int[ N ]; int *v = new int[ N ]; int mindis, minone;
2013-08-06 12:31:23 513
原创 杭电ACM1233(最小生成树)
#include using namespace std;#define MAXN 100#define INF 100000int cost[ MAXN ][ MAXN ];int closet[ MAXN ];int lowcost[ MAXN ];int N;int prim(int v0){ int ans = 0; int mindis, mino
2013-08-06 09:11:02 658
原创 杭电ACM1162(最小生成树)
#include #include using namespace std;#define MAXN 100#define INF 100000double x[ MAXN ];double y[ MAXN ];double cost[ MAXN ][ MAXN ];double lowcost[ MAXN ];int closet[ MAXN ];int n;
2013-08-06 09:09:17 483
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人