icpc:problems:usaco22open_alchemy_b
problems | |
---|---|
名称 | Alchemy B |
题目编号 | USACO22OPEN_B3 |
题目链接 | luogu.com.cn/… |
来源 | USACO |
算法分类 | DFS_枚举 |
难易程度 | 容易 |
Alchemy B
想法
尽可能去合成,只要有材料就合成。
代码实现
#include<iostream> #include<vector> using namespace std; const int N = 110; int a[N]; vector<int>p[N]; bool DFS(int x) { if(p[x].empty()) { if(a[x]) { a[x]--; return true; } else return false; } for(int i : p[x]) { if(a[i]>0) a[i]--; else { if(!DFS(i)) return false; } } return true; } int main() { int n, k, x, cnt, temp, ans; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } ans = a[n]; cin >> k; for (int i = 0; i < k; ++i) { cin >> x >> cnt ; for (int j = 0; j < cnt; ++j) { cin >> temp; p[x].push_back(temp); } } while(DFS(n)) ans++; cout << ans; return 0; }
/app/www/public/data/pages/icpc/problems/usaco22open_alchemy_b.txt · 最后更改: 2023/02/09 08:10 由 温婕莺