上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 57 下一页

2011年7月22日

poj 2531 Network Saboteur

摘要: #include<iostream> //dfs,实质是利用dfs生成组合数using namespace std;int ans[25],n,matrix[21][21],sum;void dfs(int b){ if(b>n) { int s=0; for(int i=1;i<=n;++i) if(ans[i]==1) for(int j=1;j<=n;++j) if(ans[j]==0) s+=matrix[i][j]; sum=max(sum,s); } for(int i=b;i<=n;++i) { if(ans[i]==1) continue; 阅读全文

posted @ 2011-07-22 19:47 sysu_mjc 阅读(144) 评论(0) 推荐(0) 编辑

poj 2454 Jersey Politics

摘要: #include<iostream> //随机化算法#include<algorithm>#include<vector>using namespace std;struct node{ int num;int idx; bool operator<(const node& o) { return num<o.num; }}data[200];int ans[200];int main(){ int k; cin>>k; for(int i=1;i<=3*k;++i) { cin>>data[i].num; 阅读全文

posted @ 2011-07-22 19:46 sysu_mjc 阅读(155) 评论(0) 推荐(0) 编辑

poj 2506 Tiling

摘要: // 题意: 在一个2*n的矩形中放置2*2和2*1的矩形,问有多少种放置方法,方程 ans[b]=ans[b-1]+2*ans[b-2]#include <iostream>#include <string>using namespace std;int compare(string str1, string str2){ while(!str1.empty()&&str1[0]=='0') { str1.erase(0,1); } while(!str2.empty()&&str2[0]=='0') { 阅读全文

posted @ 2011-07-22 19:46 sysu_mjc 阅读(171) 评论(0) 推荐(0) 编辑

poj 2243 Knight Moves

摘要: // 题意:图的大小8*8,可以向 8 个方向移动,求起点到终点的最短移动距离 #include <iostream> // BFS#include <string>using namespace std;const int L=8;int q[L*L],vis[L][L],dist[L][L];const int dx[]={-1,-2,-2,-1,1,2,2,1}; const int dy[]={-2,-1,1,2,2,1,-1,-2};int sx,sy,tx,ty;void bfs(){ vis[sx][sy]=1; dist[sx][sy]=0; ... 阅读全文

posted @ 2011-07-22 19:45 sysu_mjc 阅读(122) 评论(0) 推荐(0) 编辑

poj 1850 Code

摘要: // 题意: 输出某个str字符串在字典中的位置,// 由于字典是从a=1开始的,因此str的位置值就是在str前面所有字符串的个数+1// 规定字典的字符串必须是严格升序排列,其他是非法字符串,直接输出0即可// 例: a = 1; … z = 26; ab = 27, … az = 51; vwxyz = 83681;#include <iostream> //组合数学#include <string>using namespace std;int C(int n,int m) //求组合数C(n,m)=C(n-1,m)+C(n-1,m-1){ if(m=... 阅读全文

posted @ 2011-07-22 19:12 sysu_mjc 阅读(147) 评论(0) 推荐(0) 编辑

poj 2084 Game of Connections

摘要: #include <iostream> //高精度 组合数学,Catalan数,公式:An=A(n-1)*(4n-2)/(n+1)#include <string>#include<algorithm>using namespace std;int compare(string str1, string str2){ while(str1[0]=='0') { str1.erase(0,1); } while(str2[0]=='0') { str2.erase(0,1); } if(str1.size() > str2 阅读全文

posted @ 2011-07-22 19:12 sysu_mjc 阅读(222) 评论(0) 推荐(0) 编辑

poj 1804 Brainman

摘要: #include <iostream> //水题,冒泡排序,直接给出交换的次数using namespace std;int main(){ int t,n,arr[1005]; cin>>t; for(int f=1;f<=t;++f) { cin>>n; for(int i=0;i<n;++i) cin>>arr[i]; int num=0,j; for(int i=1;i<n;++i) { j=i; while(j>0&&arr[j]<arr[j-1]) { swap(arr[j],arr[j- 阅读全文

posted @ 2011-07-22 19:11 sysu_mjc 阅读(119) 评论(0) 推荐(0) 编辑

poj 1837 Balance

摘要: #include<iostream> //dpusing namespace std;const int m=7505;int w[25],hook[25],dp[25][2*m];int main(){ int c,g,i,j,k; cin>>c>>g; for(i=1;i<=c;++i) { cin>>hook[i]; } for(i=1;i<=g;++i) { cin>>w[i]; } for(i=1;i<=c;++i) dp[1][hook[i]*w[1]+m]++; //+m 使得dp数组的下标可以不小于0 阅读全文

posted @ 2011-07-22 19:11 sysu_mjc 阅读(114) 评论(0) 推荐(0) 编辑

poj 1496 Word Index

摘要: // 题意: 输出某个str字符串在字典中的位置,// 由于字典是从a=1开始的,因此str的位置值就是在str前面所有字符串的个数+1// 规定字典的字符串必须是严格升序排列,其他是非法字符串,直接输出0即可// 例: a = 1; … z = 26; ab = 27, … az = 51; vwxyz = 83681;#include <iostream> //组合数学#include <string>using namespace std;int C(int n,int m) //求组合数C(n,m)=C(n-1,m)+C(n-1,m-1){ if(m=... 阅读全文

posted @ 2011-07-22 19:10 sysu_mjc 阅读(167) 评论(0) 推荐(0) 编辑

poj 1745 Divisibility

摘要: #include <iostream> //dpusing namespace std;long long in[10005],dp[10005][105]; //dp[i][j]表示前i个数的组合 mod k =j 的可能数int main(){ int n,k; cin>>n>>k; for(int i=1;i<=n;++i) { scanf("%lld",&in[i]); //如果scanf("%d",&in[i]); 会WA in[i]%=k; } dp[1][(in[1]+k)%k]=1 阅读全文

posted @ 2011-07-22 19:10 sysu_mjc 阅读(119) 评论(0) 推荐(0) 编辑

上一页 1 ··· 21 22 23 24 25 26 27 28 29 ··· 57 下一页

导航