摘要: 以北大的1979为例:Red and BlackTime Limit: 1000MSMemory Limit: 30000KTotal Submissions: 17144Accepted: 9025DescriptionThere is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. 阅读全文
posted @ 2012-08-22 19:08 萧凡客 阅读(2206) 评论(0) 推荐(1) 编辑
摘要: 二维背包问题一 问题描述: 二维费用的背包问题是指: 对于每件物品,具有两种不同的费用; 选择这件物品必须同时付出这两种代价;对于每种代价都有一个可付出的最大值(背包容量)。 问怎样选择物品可以得到最大的价值。设这两种代价分别为代价1和代价2, 第i件物品所需的两种代价分别为a[i]和b[i]。两种代价可付出的最大值(两种背包容量)分别为V和U。物品的价值为w[i]。 f[i][u][v] = max(f[i-1][u][v] , w[i] + f[i-1][u-a[i]][v-b[i]]) 二 加深 同样的解决二维费用背包的只需要增加一维数组即可,即建立f[u][v]数组 当为完全背包时候, 阅读全文
posted @ 2012-08-22 18:11 萧凡客 阅读(6406) 评论(0) 推荐(0) 编辑
摘要: //0 1背包#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){ int i,j,n,v,f[1100],w[1100],p[1100]; scanf("%d",&t); while(t--) { memset(f,0,sizeof(f)); scanf("%d%d",&n,&v); for(i=0;i<n;i++) scanf("%d",&p[ 阅读全文
posted @ 2012-08-22 16:24 萧凡客 阅读(804) 评论(0) 推荐(0) 编辑
摘要: 北大:3767I Wanna Go HomeTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 2523Accepted: 1049Description 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define maxint 999999 5 int c[610][610],dist[610],p[610]; 6 void dj(int n) 7 { 8 int i,j,temp,u,s[610]; 9 for 阅读全文
posted @ 2012-08-22 08:37 萧凡客 阅读(306) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 #include<string.h> 3 4 const int max=120;//字符串大小 5 char x[max],y[max]; 6 int b[max][max]; 7 int c[max][max]; 8 int m,n; 9 10 void printstring(int i,int j)//打印最长字串11 {12 if(i==0||j==0) return;13 if(b[i][j]==1) 14 {15 printstring(i-1,j-1);16 printf("... 阅读全文
posted @ 2012-08-22 08:05 萧凡客 阅读(1678) 评论(0) 推荐(1) 编辑