随笔分类 -  DP

ACM的第三乐章---状态DP
摘要:poj 1185http://poj.org/problem?id=1185/*Problem: 1185 User: ruan123Memory: 2128K Time: 266MSLanguage: G++ Result: Accepted说下dp方程:dp[i][j][k] 为第i行状态为Sj,第i-1行状态为Sk时前i行最多能放置的炮数。 */#include <stdio.h>#include <string.h>#include <stdlib.h>int dp[105][65][65];int s[105],map[105],cnt,c[... 阅读全文

posted @ 2012-10-30 09:16 aigoruan 阅读(198) 评论(0) 推荐(0)

hdu 2242
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2242题目大意:给一个教室群,问能不能把这些教室群分成两部分,并且使两部分之间的权值差最小(每一个教室都有一定的权值);思路:先用双联通进行缩点,因为那些双向连通的教室肯定是分不开的,所以要把它们缩成一个点。之后再重新建图,遍历一次树!需要注意一点这道题的数据包含重边,需要考虑!!View Code #include<stdio.h>#include<string.h>#include<stdlib.h>const int N = 10005;struct nd{ int 阅读全文

posted @ 2012-06-18 14:34 aigoruan 阅读(151) 评论(0) 推荐(0)

hdu 3779
摘要:简单记忆化搜索View Code #include<stdio.h>#include<string.h>int as[1005],bs[1005],cs[2005],ok,n,m;char hash[1005][1005];void dfs(int x,int y,int z){ if(hash[x][y]||ok)return; if(z==n+m)ok = 1; hash[x][y] = 1; if(as[x]==cs[z]&&x<n)dfs(x+1,y,z+1); if(ok)return; if(bs[y]==cs[z]&& 阅读全文

posted @ 2012-04-27 16:19 aigoruan 阅读(142) 评论(0) 推荐(0)

hdu 1978
摘要:记忆化搜索View Code #include<stdio.h>#include<string.h>int n,m;int as[105][105],hash[105][105];int dfs(int x,int y){ int i,j; if(x==n||y==m)return 0; if(hash[x][y]) return hash[x][y]; for(i = 0; i <= as[x][y]; ++ i) for(j = 0; j <= as[x][y]; ++ j) if((i+j)&&(i+x<n)&&( 阅读全文

posted @ 2012-04-27 16:02 aigoruan 阅读(207) 评论(0) 推荐(0)

hdu 1428
摘要:记忆化搜索View Code #include<stdio.h>#include<string.h>#include<iostream>#include<queue>using namespace std;struct nd{ int x,y;};const long long inf = 0xfffffff;long long as[100][100],hash[100][100],dp[100][100];long long dx[] = {1,-1,0,0};long long dy[] = {0,0,1,-1};long long n;v 阅读全文

posted @ 2012-04-27 16:01 aigoruan 阅读(169) 评论(0) 推荐(0)

poj 1185
摘要:http://poj.org/problem?id=1185View Code /*Problem: 1185 User: ruan123Memory: 2128K Time: 266MSLanguage: G++ Result: Accepted说下dp方程:dp[i][j][k] 为第i行状态为Sj,第i-1行状态为Sk时前i行最多能放置的炮数。 */#include <stdio.h>#include <string.h>#include <stdlib.h>int dp[105][65][65];int s[105],map[105],cnt,... 阅读全文

posted @ 2012-04-05 21:37 aigoruan 阅读(147) 评论(0) 推荐(0)

poj 1321
摘要:http://poj.org/problem?id=1321在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。思路:状态dp(可dfs暴力过)View Code #include<stdio.h>#include<string.h>int dp[2][1<<9];int s[1<<9],a[10];char str[10][10];int main(){ int n=8,k; for(int i = 阅读全文

posted @ 2012-03-30 18:02 aigoruan 阅读(155) 评论(0) 推荐(0)

导航