摘要: 剪枝:当前状态已经存在了,它一定是最优值,直接返回它View Code #include <stdio.h>#define inf 0x3f3f3f3fstruct node{ int num[1000],price;}ar[105];int s,n,a[10],num[1000];int dp[6][6][6][6][6];int min(int x,int y){ return x<y?x:y;}int judge(int i){ int j; for (j=0;j<n;j++) { if(num[a[j]]<ar[i].num[a[j]])re... 阅读全文
posted @ 2011-11-30 20:11 104_gogo 阅读(198) 评论(0) 推荐(0)
摘要: 思路:按列循环,来模拟去方格的过程View Code #include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char str[55][25],tmp[55][25],ans[27];int n,flag;int judge(int x,int y,char ch){ int j; for (j=x;j<n;j++) { if (str[j][y]>='A'&&str[j][y]<='Z'& 阅读全文
posted @ 2011-11-28 19:36 104_gogo 阅读(224) 评论(0) 推荐(0)
摘要: View Code #include <stdio.h>#include <string.h>int n,m;double map[105][105];void floyd(){ int i,j,k; for (i=1;i<=n;i++) { for (j=1;j<=n;j++) { for (k=1;k<=n;k++) { if(i==j||i==k||j==k)continue; if(map[j][k]<map[j][i]*map[i][k... 阅读全文
posted @ 2011-11-26 21:06 104_gogo 阅读(187) 评论(0) 推荐(0)
摘要: 提供一组数据:输入: 2 30 1 10 0 1 10输出: Scenario #1:Steve wins with 1 solved problems and a score of 10.Scenario #2:Steve wins with 0 solved problems and a score of 0.View Code #include <stdio.h>#include <string.h>#include <algorithm>using namespace std;struct node{ int s,cnt; char name[10] 阅读全文
posted @ 2011-11-26 21:01 104_gogo 阅读(194) 评论(0) 推荐(0)
摘要: dij+记录路径View Code #include <stdio.h>#define inf 0x3f3f3f3fint k,n,path[1005],dis[1005],map[1005][1005];void dij(){ int i,j,min,minj,vis[1005]; for (i=1;i<=k;i++) { dis[i]=map[1][i]; vis[i]=0; path[i]=i; } vis[i]=1; for (i=2;i<=k;i++) { for (j=1,min=in... 阅读全文
posted @ 2011-11-26 20:55 104_gogo 阅读(242) 评论(0) 推荐(0)
摘要: 思路:此题的数据规模太大了,肯定不能去递归,最后想到下面这个办法由结果(s,e)向(1,1)推,如果s>e,s-=e;如果s<e,e-=s;但是由于数据太大了,减法要超时,所以改成除法就行了View Code #include <stdio.h>int main(){ int n,s,e,left,right,l=1,a; scanf("%d",&n); while(n--) { scanf("%d%d",&s,&e); left=right=0; while(s!=e) { if(s<e) ... 阅读全文
posted @ 2011-11-25 22:06 104_gogo 阅读(172) 评论(0) 推荐(0)
摘要: 最小的最大View Code #include <stdio.h>#include <algorithm>using namespace std;int n,c,ar[100005];void f(){ int left,right,mid,num,now,ans,i; left=0,right=ar[n-1]-ar[0]; while (left<=right) { mid=(left+right)/2; for (i=1,now=0,num=1;i<n;i++) { if(ar[i]-ar[now]>=... 阅读全文
posted @ 2011-11-25 21:58 104_gogo 阅读(221) 评论(0) 推荐(0)
摘要: 思路:有D种病毒,就有2^D种选法,当选出的病毒数为K时,就遍历这N头牛,如果有牛所携带的病毒包含在K这些病毒里面,m++;View Code #include <stdio.h>int n,d,k,Max,vis[20],a[1005][20];void f(){ int i,j,m=0; for (j=0;j<n;j++) { for (i=1;i<=a[j][0];i++) { if(!vis[a[j][i]])break; } if(i==a[j][0]+1)m++; } if(... 阅读全文
posted @ 2011-11-25 21:53 104_gogo 阅读(235) 评论(0) 推荐(0)
摘要: 把已经有的边,加入到图中,再用克鲁斯卡尔算最小生成树简单的一道题,但是我居然把输出看错意思了....View Code #include <stdio.h>#include <algorithm>using namespace std;struct node{ int s,e,len;}map[5055];int k,f[105];int cmp(node a,node b){ return a.len<b.len;}int Find(int x){ if(f[x]==x)return x; return f[x]=Find(f[x]);}int Union(in 阅读全文
posted @ 2011-11-24 16:50 104_gogo 阅读(159) 评论(0) 推荐(0)
摘要: View Code #include <stdio.h>#include <string.h>int start,end;char s[105];void p(){ int i=0; for (i=start;i<=end;i++)printf("%c",s[i]);}int main(){ int n,i,j,k,l,pre_ans,suf_ans; int pre_ar[5]={4,4,3,2,2},suf_ar[5]={2,3,3,1,4}; char prefix[5][5]={"anti","post&q 阅读全文
posted @ 2011-11-23 20:30 104_gogo 阅读(167) 评论(0) 推荐(0)