The Great Mixing
来源:互联网 发布:淘宝古着是什么意思 编辑:程序博客网 时间:2024/05/20 12:24
这道题非常有意思
#include <iostream>#include <cstring>#include <cstdio>#include <queue>#include <vector>#define inf 0x3f3f3f3fusing namespace std;int a[2234];int dp[5005];int n, k;int vis[5005];vector<int>v;int bfs() { int i, sum = 0; queue<int>q; for (i = 0; i < v.size(); i++) { int m = v[i] + 1000; if(vis[m]==0){ q.push(m); vis[m]=1; dp[m] = 1; } if(m==1000) return 1; } int temp; while (!q.empty()) { temp = q.front(); q.pop(); for (i = 0; i < v.size(); i++) { sum = temp + v[i]; if (dp[sum]>dp[temp] + 1 && sum <= 2000 && sum >= 0){ dp[sum] = dp[temp] + 1; if (sum == 1000)return 1; if (vis[sum] == 0) { q.push(sum); vis[sum] = 1; } } } } return -1;}int main(){ memset(a, 0, sizeof(a)); memset(dp, inf, sizeof(dp)); cin >> n >> k; int i, t; for (i = 1; i <= k; i++) { scanf("%d",&t); if(a[t-n+1000]==0){ v.push_back(t-n); } a[t-n+1000] = 1; } bfs(); if (dp[1000] != inf) cout << dp[1000] << endl; else cout << -1 << endl; return 0;}
0 0
- (codeforces) The Great Mixing
- The Great Mixing
- codeforces788C The Great Mixing
- CF 788C(The Great Mixing-背包)
- Codeforces Round #407 (Div. 1) C. The Great Mixing(bfs)
- Codeforces 789E The Great Mixing【Bfs+dp】
- (CF 788)C. The Great Mixing <BFS>
- CF788C:The Great Mixing(背包bitset & bfs)
- Codeforces Round #407 (Div. 2) E. The Great Mixing [bfs]
- codeforces 788C The Great Mixing (bitset优化dp、bfs)
- BFS (图)——Codeforces 788 C. The Great Mixing
- Codeforces 789E The Great Mixing (数推倒公式 + bfs + 剪枝)
- Codeforces Round #407 (Div. 2)-E-The Great Mixing-滚动数组或者dfs
- codeforces 788C The Great Mixing( BFS / dp+bitset优化 )
- [BFS] Codeforces Round #407 (Div. 1) 788C. The Great Mixing
- The Great XOR (HackerRank the-great-xor)
- The Great St.Brmard
- FFMpeg,the Great.
- 关于使用EL语句来接收servlet给jsp传递及jsp页面之间传递的数据
- ReactNative 定位问题
- 面向对象的特征有哪些
- mysql中的group by,having,order by,where用法
- Windows Server 2008 R2 WEB 服务器安全设置指南(三)之文件夹权限设置
- The Great Mixing
- C++虚函数的原理
- python标准库之zipfile
- Python入门
- 知识点积累
- android 手机内置,sd卡存储的存储路径和空间问题
- PHP高级应用
- AS
- php 多进程函数 pcntl