摘要: http://poj.org/problem?id=1466题意:从n个男女同学中找出两两没有任何关系的最大人数。使用C++输入输出,WA了好几次,改了用C就过,也不知道怎么回事,好气愤啊!!!Sample Input70: (3) 4 5 61: (2) 4 62: (0)3: (0)4: (2) 0 15: (1) 06: (2) 0 130: (2) 1 21: (1) 02: (1) 0Sample Output52Source Code#include <iostream>using namespace std;const int N = 600;int pic[N][N 阅读全文
posted @ 2011-04-27 18:25 Pengchao Bai 阅读(267) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <string>using namespace std;const char c = 'a';//根据情况,可以改为 'A'struct TrieNode{TrieNode *next[26];int cnt;TrieNode(){cnt=0;for(int i=0;i<26;i++){next[i]=NULL;}}}*trieRoot = new TrieNode;void trieInsert(TrieNode *root, string s){//字符串插入for(int 阅读全文
posted @ 2011-04-27 11:04 Pengchao Bai 阅读(151) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;const int N = 1000;int p[N],rank[N];void init(int n){//把每个点所在集合初始化为其自身for(int i=1;i<=n;i++){p[i]=i;rank[i]=0;}}int find(int i){//查找元素所在的集合,即根节点if(p[i]!=i)p[i]=find(p[i]);return p[i];}void merge(int i, int j){//将两个元素所在的集合合并为一个集合。i=find(i);j=find(j);if(i 阅读全文
posted @ 2011-04-27 10:30 Pengchao Bai 阅读(143) 评论(0) 推荐(0) 编辑
摘要: /**背包状态转移方程:*if(weight[i]>j) dp[i][j]=dp[i-1][j];*else dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight[i]]+value[i]);*/#include <iostream>using namespace std;const int N = 1000;const int M = 10000;int w[N],v[N],dp[M];int max(int a,int b){return a>b?a:b;}int main(){int n,m,i,j;cin>>n> 阅读全文
posted @ 2011-04-27 09:31 Pengchao Bai 阅读(134) 评论(0) 推荐(0) 编辑