上一页 1 ··· 11 12 13 14 15
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1010一道深搜+剪枝 纠结了一晚上加一上午 。。。开始自己写的代码没过 后来又看了xcy学长(xcyx学长的代码很清晰 简洁 实在佩服 在此表示崇拜)的 结题报告写的 中间还是改了很长时间错误 足见代码功底有多差了 代码:#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int visit[11][11], XX[4]={1,-1,0 阅读全文
posted @ 2011-11-22 11:51 快乐. 阅读(186) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3628给N个数 和一个 B,从N个数中 选 出一些数 求和 sum 让sum>=B 求sum最小01背包代码:#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>const int inf=20000002;using namespace std;int a[21],dp[inf+1];int N,B,sum;void _01pack(){ dp[0]=0; int i,j,k; for(i=1;i& 阅读全文
posted @ 2011-11-20 22:00 快乐. 阅读(377) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1102最小生成树 (prim)代码:#include<cstdio>#include<iostream>const int inf=1002;using namespace std;int a[101][101],dis[101],visit[101];int prim(int N)//1为原点{ int i,sum,min,mark,j,k; for(i=2;i<=N;i++) dis[i]=a[1][i]; dis[1]=0; visit[1]=1; ... 阅读全文
posted @ 2011-11-20 01:08 快乐. 阅读(145) 评论(0) 推荐(0) 编辑
摘要: sort()排序 从首地址 最后一个数地址的下一个如int a[6]={ 4,2,5,0,8,6};sort(a+1,a+5); 参加排序的数为 2 5 0 8qsort() 快速排序七种qsort排序方法 <本文中排序都是采用的从小到大排序> 一、对int类型数组排序 程序代码int num[100]; Sample: int cmp ( const void *a , const void *b ) { return *(int *)a - *(int *)b; } qsort(num,100,sizeof(num[0]),cmp);二、对char类型数组排序(同int类型) 阅读全文
posted @ 2011-11-19 20:38 快乐. 阅读(147) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3664DP代码三种情况dp[i][j]表示i个数中E为 j 的个数 加入第 i+1个数时 有三种情况 1.第 i+1个数放在最后 为dp[i-1][j] 2. i+1个数 和 a[i]>i的数交换 dp[i-1][j]*j 3.i+1个数和 a[i]<=i 的数交换dp[i-1][j-1]*[i-j] 则状态转移方程为 dp[i][j]=(dp[i-1][j]+dp[i-1][j]*j+dp[i-1][j-1]*(i-j))mod 1000000007;#include<iostream&g 阅读全文
posted @ 2011-11-19 19:55 快乐. 阅读(161) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3661贪心正排 倒排 相加代码#include<iostream>#include<algorithm>using namespace std;int a[1002],b[1002];int main(){ int N,T,i; while(scanf("%d%d",&N,&T)!=EOF) { int sum=0; for(i=1;i<=N;i++) scanf("%d",&a[i]); sort(a+1,a+N+ 阅读全文
posted @ 2011-11-19 19:45 快乐. 阅读(154) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3665最短路代码(spfa)#include<iostream>#include<cstdio>#include<string>#include<cstring>#define nMAX 12#define inf 1<<30using namespace std;int vs[nMAX],head[nMAX],dis[nMAX],sea[nMAX],qu[nMAX];int n,s_edge;struct Edge{ int u,v,w,nxt;} 阅读全文
posted @ 2011-11-19 19:38 快乐. 阅读(175) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3258题意:河宽L(左岸 右岸各有一块石头)河中有N 个石头,每个石头距离河岸有一定的距离, 移走M个石头(只移河中的石头) 求两块石头的距离 中最短的关键是开始不知道用二分解代码写起来还算简单 就是二分的思路。。。代码:#include<iostream>#include<algorithm>using namespace std;int a[50002];int L,N,M;bool can_cross(int mid){ int i,start=0,sum=0; for(i=1;i<=N;i++) { . 阅读全文
posted @ 2011-11-18 20:09 快乐. 阅读(226) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4004青蛙过河河的宽度L 有N块石头 青蛙最多可跳M次 ,求青蛙的最小弹跳能力代码(一)#include<iostream>#include<algorithm>using namespace std;int a[500005],L,N,M;int can_cross(int mid){ int i,start=0,m=0; for(i=1;i<=N;i++) { if(a[i+1]-a[i]>mid)return false; if((a[i]-start<=mi. 阅读全文
posted @ 2011-11-18 18:50 快乐. 阅读(295) 评论(0) 推荐(0) 编辑
上一页 1 ··· 11 12 13 14 15