HDU1518 Square

http://acm.hdu.edu.cn/showproblem.php?pid=1518 DFS 开始的时候回朔问题没有考虑清楚 #include<stdio.h>#include<stdlib.h>#include<string.h>int stick[22];int k[22];int n,sum,average,temp; int cmp ( const void *a , const void *b ){ return *(int *)b - *(int *)a;} void dfs(int numbers,int sticks,int real_time_sum...
2008-05-16 14:09 | 阅读 4218 次 | 评论 0 条

HDU 2169Geek Challenge [SKRZAT] (Base Minus Two)

http://acm.hdu.edu.cn/showproblem.php?pid=2169 #include<stdio.h>#include<string.h>int main(){ int n,i,j,k,sum,len,q,w = 1,p; char c,a[16]; scanf("%d",&amp;n); while(n--) { getchar(); scanf("%c ",&amp;c); if(c=='b') { k=1; sum=0; scanf("%s",a); len=strlen(a); for(i=len-1;i>=0;i--) ...
2008-05-15 09:31 | 阅读 3525 次 | 评论 0 条

HDU 1176 免费馅饼

http://acm.hdu.edu.cn/showproblem.php?pid=1176 简单dp #include<stdio.h>#include<string.h>int fallx[100010][11];int a[100001][11];int main(){ int i,n,x,t,max,total,sum,q,j; while (scanf("%d",&amp;n)!=EOF&amp;&amp;n){ memset(fallx,0,sizeof(fallx)); memset(a,0,sizeof(a)); for(max=0,i=0;i<n;i++){ ...
2008-05-13 11:16 | 阅读 4331 次 | 评论 0 条

HDU 1058Humble Numbers

http://acm.hdu.edu.cn/showproblem.php?pid=1058 水题 也贴一下 #include<stdio.h>int humble[5843];int min(int a, int b, int c, int d){ a=a>b?b:a; a=a>c?c:a; a=a>d?d:a; return a;}void main(){ int e1=1,e2=1,e3=1,e4=1,a1,a2,a3,a4,i,n; humble[1]=1; for(i=2;i<=5842;i++) { a1=2*humble[e1];...
2008-05-13 10:54 | 阅读 3791 次 | 评论 1 条

HDU 1799 循环多少次?

http://acm.hdu.edu.cn/showproblem.php?pid=1799 公式推出来以后就是简单题了,呵呵 就是求n! / (m)! / (n-m)! 简单来说就是求C(n)m #include <stdio.h>int c[2002][2002] = {0};int main(){ int i,j,t,n,m; for(i=1;i<=2000;i++) { c[i][0]=1; c[i][1]=i%1007; } for(i=2;i<=2000; i++) for(j=2;j<...
2008-05-13 09:06 | 阅读 3507 次 | 评论 0 条

HDU1232 畅通工程

http://acm.hdu.edu.cn/showproblem.php?pid=1232 赤裸裸的并查集 #include<stdio.h>int a[1010];int findx(int x){ while(a[x]!=x) //寻找根节点 x=a[x]; return x;}void merge(int x,int y){ int fx,fy; fx=findx(x); fy=findx(y); if(fx!=fy) a[fx]=fy;}int main(){ int n,m,count,i,x,y; while(scanf("%d",&amp;n)!=...
2008-05-12 14:42 | 阅读 3087 次 | 评论 0 条

HDU 1692 Destroy the Well of Life

http://acm.hdu.edu.cn/showproblem.php?pid=1692 模拟题 比赛的时候居然没有看这道题 哎 还是卡死在那个一直被我们认为是dp的该死的floyed上了啊 #include<stdio.h>int w[100001];int l[100001];int p[100001];int main(){ int n,t,k=0,j,i,min,energy,water; scanf("%d",&amp;t); while(t--) { k++; scanf("%d",&amp;n); for(i=1;i<=n;i++) scanf("%...
2008-05-12 10:55 | 阅读 2987 次 | 评论 0 条

PKU 1160 Post Office

http://acm.pku.edu.cn/JudgeOnline/problem?id=1160 DP题 在一条笔直的公路上有一排城镇,要在城镇上建邮局,首先输入城镇数和要建的邮局数,问:所有城镇距离最近邮局的距离总和是多少? 题目思路:用w[i][j]记录把前i个邮局建到前j个村庄中的最优解,用distance[i][j]记录所有在i到j村庄中,建1个邮局的最小代价。显然邮局应该设到中点。让前i个邮局覆盖前j个村庄,第i+1个邮局覆盖第j+1至j+k个村庄(j+k<=n),则状态转移方程为w[i+1][j+k]=min{w[i][j]+distance[j+1][j+k];} ...
2008-05-11 21:09 | 阅读 5357 次 | 评论 0 条

HDU 1690 Bus System

http://acm.hdu.edu.cn/showproblem.php?pid=1690 才做了几天的DP专题,昨天的杭电全国邀请赛上居然就从头到尾都把它当DP做了 队里的3个人居然还会一致认为是DP,郁闷啊。。。。 其实只要floyed就可以过了的。。。。想复杂了啊。。。。。 #include<stdio.h>#include<string.h>__int64 l[5],c[5];__int64 cost(__int64 len){ if(len==0) return 0; else if(len<=l[1]) return c[1]; else if(len<=l[2...
2008-05-11 13:15 | 阅读 1745 次 | 评论 0 条

HDU 1466计算直线的交点数

//相交直线数 http://acm.hdu.edu.cn/showproblem.php?pid=1466 典型的DP #include<stdio.h>int main(){ int i,j,n,f[21][191]; //f[i][j]表示i条边时,是否能产生j个结点,能,返回1,不能,返回0 for(i=0;i<21;i++) for(j=0;j<191;j++) f[i][j]=(j==0); //f[i][0]都置1 for(n=2;n<21;n++) for(i=n-1;i>=1;i--) for(j=0;j<191;j++) if(f[n...
2008-05-08 21:39 | 阅读 3318 次 | 评论 1 条

HDU 1788 Chinese remainder theorem again

http://acm.hdu.edu.cn/showproblem.php?pid=1788 简单题 不过一开始还是被迷惑住了 以为是用中国剩余定理写的 不过后来发现原来只要求所有数的最大公约数减去a就是结果了 #include<stdio.h>__int64 gcd(__int64 a,__int64 b){ if(b==0)return a; else return gcd(b,a%b);}int main(){ __int64 n,a,k1,k2,k[10],i; while(scanf("%I64d%I64d",&amp;n,&amp;a)!=EOF&amp;&a...
2008-05-07 11:06 | 阅读 1677 次 | 评论 0 条

pku 1006Biorhythms

http://acm.pku.edu.cn/JudgeOnline/problem?id=1006 这道题是用中国剩余定理写的 直接套用公式了。。。。。 #include <stdio.h>int main(){ int p,e,i,d,a,t=0; while(scanf("%d%d%d%d",&amp;p,&amp;e,&amp;i,&amp;d)!=EOF) { if(p==-1&amp;&amp;e==-1&amp;&amp;i==-1&amp;&amp; d==-1)break; a=(5544*p+14421*e+1288*i-d+21252)%21252; i...
2008-05-06 22:38 | 阅读 2517 次 | 评论 0 条

HDU 1684 Projects

http://acm.hdu.edu.cn/showproblem.php?pid=1684 这是一个二维的DP简单题 最近在做DP专题 呵呵 还是第一次做到二维的呢 爽 A题不多 只求在比赛前能多熟悉下DP的各种类型。。。。。 #include<stdio.h>#include<string.h>int p[101][101];int dp[101][101];int a[101];int reward[101];int punishment[101];int main(){ int m,n,t,max,i,j,k,salary,w; scanf("%d",&a...
2008-05-05 22:26 | 阅读 1429 次 | 评论 0 条

ZJU 2956Another Horizontally Visible Segments

http://acm.zju.edu.cn/show_problem.php?pid=2956 这道题很郁闷啊 ,当时题目居然看错了,一开始的时候是理解对的 ,后来发现x输入怎么一点用都没有的,就开始郁闷了,这道题有这么难么??都怪自己审题不清,还不肯重新看题。。。。 #include<stdio.h>#include<string.h>int count[10001];int main(){ int T,n,i,x[4001],y1[4001],y2[4001],sum,max; scanf("%ld",&amp;T); while (T--) { scanf("%d",&amp...
2008-05-02 19:14 | 阅读 2444 次 | 评论 4 条

ZJU2014 Piggy-Bank

http://acm.zju.edu.cn/show_problem.php?pid=2014 这些天在做DP专题,所以从HDU转战到ZJU找DP,没想到第一个就A到这道题,感觉有点变态! 这道DP花了我三天时间(资质比较差,没办法),终于搞定了,哈哈!!! 其实前几天我A的几个DP都是一个模板的,核心思想都是一个模板的。而这道题有点区别: 1、题目要求是在存钱罐里存入一定质量的钱,使得最少可以存钱 2、存钱罐必须存满 #include<stdio.h>#include<string.h>int p[10001],q[10001];int price[501],weight[...
2008-04-28 20:14 | 阅读 2857 次 | 评论 1 条

HDU1203 I NEED A OFFER!

http://acm.hdu.edu.cn/showproblem.php?pid=1203 虽然是01背包问题,但是完全可以用贪心解决此题,如果用了动态,我认为反而把简单问题麻烦化了 此解法时间效率不高,有时间再重新看看…… #include<stdio.h>int main(){ int m,n,a[1001],i,j,t; double b[1001],k[1001],t1,s; while(scanf("%d%d",&amp;m,&amp;n)!=EOF&amp;&amp;!(m==0&amp;&amp;n==0)) { for(i=1...
2008-04-28 09:42 | 阅读 4409 次 | 评论 0 条

HDU1244 Max Sum Plus Plus Plus

http://acm.hdu.edu.cn/showproblem.php?pid=1244 #include< stdio.h >#include< string.h >int am[ 21 ]={0}, ansum[ 1001 ]={0}, lenam[ 21 ]={0}, an[ 1001 ]={0}, sum[ 21 ][ 1001 ]={0};int main( ){ int max, i, j, max_res, n, m; while( scanf( "%d", &amp;n ) != EOF &amp;&amp; n ) { scanf( "%d", &amp;m )...
2008-04-26 18:38 | 阅读 3225 次 | 评论 0 条

HDU1003--Max Sum

http://acm.hdu.edu.cn/showproblem.php?pid=1003 #include<stdio.h>#include<string.h>int a[100001];void biggest(int w){ int i,m,r,s1,e1,s,e; r=-1000; m=0; s=1;e=1; s1=1;e1=1; for(i=1;i<=w;i++) { if(m>=0){m+=a[i];e=i;} else if(m<0){m=a[i];s=i;e=i;} if(m>r){s...
2008-04-26 18:36 | 阅读 1326 次 | 评论 0 条

HDU 1257 最少拦截系统

http://acm.hdu.edu.cn/showproblem.php?pid=1257 求最长不降子序列问题 #include<stdio.h>#include<string.h>int c[1001][1001];int main(){ char a[1001],b[1001]; int i,j,la,lb; while(scanf("%s %s",a,b)!=EOF) { la=strlen(a); lb=strlen(b); for(i=0;i<la;i++)c[i][0]=0; for(i=0;i<lb;i++)c[0][i]=0; for(i=1;i<=la...
2008-04-26 18:31 | 阅读 1931 次 | 评论 0 条

HDU 1723---Distribute Message

http://acm.hdu.edu.cn/showproblem.php?pid=1723 #include<stdio.h>#include<string.h>int main(){ int n,m,a[31],i,j,b; while(scanf("%d%d",&amp;n,&amp;m)!=EOF) { if(n==0&amp;&amp;m==0)break; for(i=0;i<31;i++) a[i]=1; for(i=n-1;i>0;i--) { b=0; for(j=i+1;j<=n&amp;&amp;j-i<=m;j++) b=b+a[j]*...
2008-04-26 18:29 | 阅读 1047 次 | 评论 1 条
最新评论