摘要: 听说这是个LIS的题,画了画图,发现是这样的..View Code #include <stdio.h>int ar[500005],vis[500000];int main(){ int n,i,j,k,m,p,r,l=1; while (scanf("%d",&n)!=EOF) { for (i=0;i<n;i++) { scanf("%d%d",&p,&r); ar[p]=r; } for (i=1,j=0,m=0;i<=n;i++) { ... 阅读全文
posted @ 2011-11-12 10:52 104_gogo 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 0-1背包View Code #include <stdio.h>#include <string.h>int max(int a,int b){ return a>b?a:b;}int main(){ int T,i,j,n,V,a,val[1005],dp[1005]; scanf("%d",&T); while (T--) { scanf("%d%d",&n,&V); memset(dp,0,sizeof(dp)); for (i=0;i<n;i++)scanf("%d" 阅读全文
posted @ 2011-11-12 09:34 104_gogo 阅读(124) 评论(0) 推荐(0) 编辑
摘要: dp[i]+=dp[i-j];dp[i]表示传到第i个位置有多少种方法View Code #include <stdio.h>#include <string.h>int main(){ int n,m,i,j,dp[40]; while (scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0)break; memset(dp,0,sizeof(dp)); dp[1]=1; for (i=2;i<=n;i++) { for (j=0;j<=m;j++) ... 阅读全文
posted @ 2011-11-12 09:18 104_gogo 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 告诉一个n*m*k的长方体用手扳:次数=(n-1)+(m-1)*n+(k-1)*n*m;//化简后居然是:n*m*k-1;把一个n*m*k的方块先扳n-1次,得到n个小方块,再把它们每个扳m-1下,得到n*m个小方块,最后把它们每个扳k-1下,这样每个方块都是1*1*1的了。用刀切:打表用刀的时候,这道题其实就变成了这样一个问题:给你3条直线,要求把每条直线切成长度为1的小段,最少切多少刀?长度 1 2 3 4 5 6 7 8 9 10切的次数 0 1 2 2 3 3 3 3 4 4不难发现 dp[i*2]=... 阅读全文
posted @ 2011-11-11 17:25 104_gogo 阅读(325) 评论(0) 推荐(0) 编辑
摘要: 一开始想用多次求最长下降子序列方法做:有多少个最长下降子序列,就需要多少台系统。但是wa了然后就想到,保存每台系统能发射的最大高度h[i],如果某个导弹的高度H>所有h[i],则需要添加一台系统了;否则,h[i]=H(h要排序,贪心)View Code #include <stdio.h>#include <algorithm>using namespace std;int main(){ int n,m,i,j,min,h[10000],ar[10000]; while (scanf("%d",&n)!=EOF) { for (i=0 阅读全文
posted @ 2011-11-10 20:05 104_gogo 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 把花生数按从大到小排序,然后一个一个的去试,能摘就摘,不能摘就结束了.View Code #include<cstdio>#include<cmath>#include<algorithm>using namespace std;struct node{ float x,y; int num;}a[2505];float cmp(node x,node y){ return x.num>y.num;}int main(){ int i,j,k,n,r,c,num,ans,len,step,limit; scanf("%d",& 阅读全文
posted @ 2011-11-10 14:10 104_gogo 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 记忆化dfs当搜索到一个位置,如果这个位置的下面已经被搜索过了,则直接返回它的值View Code #include <stdio.h>#include <string.h>int n;__int64 vis[36][36];char board[36][36];__int64 dfs(int x,int y){ int i; if(x==n-1&&y==n-1)return 1; if(board[x][y]=='0')return 0; if(vis[x][y])return vis[x][y]; if(x+board[x][y]-& 阅读全文
posted @ 2011-11-10 11:56 104_gogo 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 0-1背包dp[i]=max(dp[i],1-(1-dp[i-a])*(1-b));dp[j]表示当选择一所学校,用 i 这么多钱的时候他可以收到至少一份offer的最大概率View Code #include <stdio.h>#include <string.h>float max(float a,float b){ return a>b?a:b;}int main(){ int n,m,i,j,a; float b,dp[10005]; while (scanf("%d%d",&n,&m)!=EOF) { if(n==0& 阅读全文
posted @ 2011-11-10 10:01 104_gogo 阅读(167) 评论(0) 推荐(0) 编辑
摘要: dp[i][j]=max(dp[i-1][j-1],dp[i-1][j],dp[i-1][j-1]);如果这个位置能接到馅饼,则还要加上现在接的:dp[i][j]+=vis[i][j];dp[i][j]表示第i秒j位置最多的馅饼数View Code #include <cstdio>#include <algorithm>using namespace std;int vis[100005][15],dp[100005][15];int main(){ int i,j,n,x,t,time,ans; while(scanf("%d",&n)& 阅读全文
posted @ 2011-11-09 14:39 104_gogo 阅读(99) 评论(0) 推荐(0) 编辑
摘要: dp[i]=max(dp[i-1],能匹配成的单词的最长长度+i);View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 5 using namespace std; 6 7 int n,len,ar[205]; 8 char s[205][15],str[200005]; 9 10 int judge(int i)11 {12 int j,k,l,MAX=0;13 for (j=0;j<n;j++)14 {15 for (k=i,l=0;l<a 阅读全文
posted @ 2011-11-01 15:56 104_gogo 阅读(123) 评论(0) 推荐(0) 编辑