2013年8月14日
摘要: 由于第一位上不能为零 所以需要枚举这种dp[1][i] 状态转移方程dp[i][j]=d[i+1][0....k-1]#include #include #include int dp[20][20];int n,k;int dfs(int x,int y){ if(x==n) return dp[x][y]=1; if(dp[x][y]!=-1) return dp[x][y]; dp[x][y]=0; for(int i=1; i<k; i++) dp[x][y]+=dfs(x+1,i); if(y) dp[x][y]+=dfs(x... 阅读全文
posted @ 2013-08-14 11:51 风流monkey 阅读(141) 评论(0) 推荐(0) 编辑
  2013年8月13日
摘要: 直接暴就可以了 可是自己超时,在于定义结构体的时候 不要把球队的名字放进去 ,自己在回溯的时候不断的将结构体相互赋值导致了超时。。。。#include #include #include using std::sort;struct dat{ int socer; int top; int low; int number; bool operatorq.socer;}int ans[33];void dfs(int x){ if(x==q) { for(int i=0; ipp) b[i].top=pp; ... 阅读全文
posted @ 2013-08-13 11:56 风流monkey 阅读(175) 评论(0) 推荐(0) 编辑
  2013年8月12日
摘要: 最长上升子序列 先对维数进行排序 然后再对几个盒子进行排序 最后利用vis数组来存路径 最后就是利用回溯来输出路径#include #include #include #include using namespace std;struct dat{ int num[30]; int number;} a[33];int n,m;int dp[33];int vis[33],st;bool cmp(dat p, dat q){ for(int i=0; i=q.num[i]) return false; return true;}void dfs(i... 阅读全文
posted @ 2013-08-12 20:39 风流monkey 阅读(132) 评论(0) 推荐(0) 编辑
  2013年8月10日
摘要: 简单的动规 就是枚举起点(第一列) 然后找出最小值 英语是硬伤 最小字典序这个问题竟然没注意到 状态转移方程dp[i][j]=min(dp[i+1][j+1],dp[i][j+1],dp[i-1][j+1]);路径用个二维数组记录下就可以了!#include #include #include #include int vis[110][110];int dp[110][110];int a[110][110];int move[3]={-1,0,1};int n,m;int dfs(int x, int y){ if(y==m) return dp[x][y]=0; if(dp... 阅读全文
posted @ 2013-08-10 19:06 风流monkey 阅读(215) 评论(0) 推荐(0) 编辑
  2013年8月9日
摘要: dp 状态转移方程 dp[i][j]=max(dp[i][j],dp[i][k](*/+)dp[k+1][j]) , dp[i][j]=min(dp[i][j],dp[i][k](*/+)dp[k+1][j]) 和uva 上的10700非常相似 但是 spoj上有数字0所以就不能用简单的栈的思想来做了 选择用dp来做#include #include #include #include using namespace std;long long a[110];long long b[110];long long dp[110][110];bool vis[110][110];char s[11 阅读全文
posted @ 2013-08-09 21:06 风流monkey 阅读(161) 评论(0) 推荐(0) 编辑
  2013年8月8日
摘要: 背包#include #include int coin[]={5,10,20,50,100,200,500,1000,2000,5000,10000};long long dp[11][30010];char s[10];int solve(){ int i=0; int sum=0; for(i=0; s[i]!='.'; i++) sum=sum*10+s[i]-'0'; for(int j=i+1; s[j]!='\0'; j++) sum=sum*10+s[j]-'0'; return sum;}long long df 阅读全文
posted @ 2013-08-08 16:37 风流monkey 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 昨天太着急 没注意数据的范围直接用dp数组直接用int 了 今天想了一下 应该用long long#include #include int coin[5]= {1,5,10,25,50};long long dp[5][30010];long long dfs(int cur,int sum){ if(sum==0) return dp[cur][sum]=1; if(dp[cur][sum]!=-1) return dp[cur][sum]; dp[cur][sum]=0; for(int i=cur; i=coin[i]) ... 阅读全文
posted @ 2013-08-08 16:06 风流monkey 阅读(130) 评论(0) 推荐(0) 编辑
  2013年8月3日
摘要: 二分查找最小值#include #include #include #define N 100010using std:: sort;int a[N];int n,m;int solve(int x){ int cas=0; int nx=1; for(int i=2; i=x) { cas++; nx=i; } } return cas+1;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d ... 阅读全文
posted @ 2013-08-03 20:10 风流monkey 阅读(183) 评论(0) 推荐(0) 编辑