上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 57 下一页

2011年8月23日

完全背包之三

摘要: //poj 3260 The Fewest Coins/*题意:John带了n种币值Vi的确定数量Ci的硬币,而shopkeeper的硬币无限多.给出T,求John支付的硬币数目加上售货员找零的硬币数目的最小值。如果无法支付T,输出-1 支付时硬币数量有限制,为多重背包问题. 找零时硬币数量无限制,为完全背包问题*/#include<iostream> //多重背包和完全背包using namespace std; int main() { int n,t,euro[110],num[110],dp[30000],maxn; cin>>n>>t; i... 阅读全文

posted @ 2011-08-23 17:12 sysu_mjc 阅读(164) 评论(0) 推荐(0) 编辑

完全背包之一

摘要: #include<iostream> //poj 2063 Investmentusing namespace std;int dp[5000000];int main(){ int n,t,d,v,bond[50],interest[50]; cin>>n; while(n--) { cin>>v>>t>>d; for(int i=1;i<=d;++i) { cin>>bond[i]>>interest[i]; bond[i]/=1000; ... 阅读全文

posted @ 2011-08-23 17:11 sysu_mjc 阅读(121) 评论(0) 推荐(0) 编辑

完全背包之二

摘要: //sicily 2014. Dairy Queen#include<iostream> //动态规划,给出几种不同硬币,求组成总值n有多少种方法#include<cstring>using namespace std;int main(){ int n,c,dp[400],w[10]; cin>>n>>c; for(int i=0;i<c;++i) cin>>w[i]; memset(dp,0,sizeof(dp)); dp[0]=1; for(int i=0;i<c;++i) //类似于完全背包问题 ... 阅读全文

posted @ 2011-08-23 17:11 sysu_mjc 阅读(128) 评论(0) 推荐(0) 编辑

统计短文中各字符的频度

摘要: //主要算法,二叉排序树的查找//以出现的各字符构成一棵二叉排序树,针对每一个字符在二叉树中查找,如果找到了就增加计数,否则就插入#include<iostream>#include<string>#include<fstream>using namespace std;typedef char KeyType;struct BstNode { KeyType data; int num; BstNode *lch,*rch;};class BstTree{private: BstNode *root; BstNode* insert(BstNode *t, 阅读全文

posted @ 2011-08-23 17:08 sysu_mjc 阅读(261) 评论(0) 推荐(0) 编辑

随机化算法之三

摘要: #include <iostream> //poj 3318using namespace std;int ma[505][505],mb[505][505],mc[505][505],n;int main(){ scanf("%d",&n); for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) scanf("%d",&ma[i][j]); //cin 会TLE for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) ... 阅读全文

posted @ 2011-08-23 17:07 sysu_mjc 阅读(158) 评论(0) 推荐(0) 编辑

随机化算法之四

摘要: #include<iostream> //随机化算法 poj 2454#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>>d... 阅读全文

posted @ 2011-08-23 17:07 sysu_mjc 阅读(122) 评论(0) 推荐(0) 编辑

随机化算法之一

摘要: #include<iostream> //随机化算法,poj 2531using namespace std;int matrix[21][21];int ans[21];int main(){ int n; cin>>n; for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) cin>>matrix[i][j]; int t=200000,r,s,m=0; //WA:随机的次数不够,TLE: 由于每次都随机分配所有点的位置,所以随机次数稍多后就超时。 whi... 阅读全文

posted @ 2011-08-23 17:06 sysu_mjc 阅读(149) 评论(0) 推荐(0) 编辑

随机化算法之二

摘要: #include<iostream> //poj 2531, 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) ... 阅读全文

posted @ 2011-08-23 17:06 sysu_mjc 阅读(118) 评论(0) 推荐(0) 编辑

十进制转化为任意进制

摘要: #include<iostream>using namespace std;void decTo(int num,int base){ if(num>0) { decTo(num/base,base); if(num%base>9) cout<<static_cast<char>(num%base+55); else cout<<num%base; }}int main(){ int number,base; cout<<"Enter the number and base:"; cin>> 阅读全文

posted @ 2011-08-23 17:05 sysu_mjc 阅读(158) 评论(0) 推荐(0) 编辑

枚举之二

摘要: //poj 1166 The Clocks#include<iostream> //枚举 264K 297MS #include<string>using namespace std;string str[10]={" ","ABDE","ABC","BCEF","ADG","BDEFH","CFI","DEGH","GHI","EFHI"};int main(){ int 阅读全文

posted @ 2011-08-23 17:03 sysu_mjc 阅读(97) 评论(0) 推荐(0) 编辑

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 57 下一页

导航