poj1252 BFS
来源:互联网 发布:霍先生的安之知百度云 编辑:程序博客网 时间:2024/04/28 04:51
搜完全背包题时翻到的。。
BFS比背包高效简单多了。。
#include<iostream> #include <string> #include<vector> #include<algorithm> #include<set> #include<fstream>#include<cmath> #include<queue>using namespace std; #define lch(i) ((i)<<1) #define rch(i) ((i)<<1|1) #define sqr(i) ((i)*(i)) #define pii pair<int,int> #define mp make_pair #define FOR(i,b,e) for(int i=b;i<=e;i++) #define FORE(i,b,e) for(int i=b;i>=e;i--) #define ms(a) memset(a,0,sizeof(a)) const int maxnum =155;int tol,n,m;int dp[205];int c[7];void BFS(){queue<int> que;FOR(i,1,6){que.push(c[i]);}int lel=1;int pi;while(!que.empty()){pi=que.front();que.pop();FOR(i,1,6){if(pi-c[i]>0&&!dp[pi-c[i]]){dp[pi-c[i]]=dp[pi]+1;que.push(pi-c[i]);}if(pi+c[i]<=200&&!dp[pi+c[i]]){dp[pi+c[i]]=dp[pi]+1;que.push(pi+c[i]);}}}}int main() { //fstream fin("G:/1.txt");int t,most;cin>>t;//fin>>t;while(t--){ms(c);ms(dp);FOR(i,1,6){//fin>>c[i];scanf("%d",&c[i]);dp[c[i]]=1;}BFS();tol=0;int mn=0;FOR(i,1,100){tol+=dp[i];mn = max(mn,dp[i]);}printf("%.2f %d\n",(float)tol/100,mn);}return 0;}
0 0
- poj1252 BFS
- poj1252
- poj1252
- POJ1252 完全背包 dp 搜索 dfs bfs
- poj1252解题报告
- poj1252 Euro Efficiency
- 完全背包的变形POJ1252
- poj1252-完全背包(正负背包)
- BFS
- bfs
- BFS
- BFS
- bfs
- BFS
- bfs
- BFS
- BFS
- bfs
- hdu 4251 The Famous ICPC Team Again(划分树)
- Nginx个人调优见解
- 发布Web项目时访问域名打开首页
- iOS常用的几个动画
- java 调用webservice的各种方法总结
- poj1252 BFS
- X11: Linux跨网络运行XWindow程序
- iOS9 URLScheme白名单
- linux进程(二)之基础
- C++ 静态局部变量用法详解
- Linux LVM硬盘管理及LVM扩容
- UICollectionView请求网络数据显示(Text)
- 关于SandBox机制及文件读写的几种方式
- hdu 2011