蓝桥集训之母亲的牛奶
-
核心思想: 暴搜 + bfs/dfs
- bfs: 将每种情况搜索一遍
-
#include <cstdio>#include <algorithm>#include <cstring>#include <iostream>using namespace std;const int N = 21;int A,B,C;struct Node{int a,b,c;}q[N*N*N];bool vis[N][N][N]; //是否出现过该情况int hh,tt; //数组模拟队列void insert(int a,int b,int c){if(!vis[a][b][c]){q[++tt] = {a,b,c};vis[a][b][c] = true;}}void bfs(){q[0] = {0,0,C};vis[0][0][C] = true;while(hh<=tt){auto t = q[hh++];int a = t.a , b= t.b , c = t.c;//a往b倒insert(a - min(a, B - b), min(a + b, B), c);//a往c倒insert(a- min(a, C - c), b, min(a + c, C));//b往a倒insert(min(a + b, A), b - min(b, A - a), c);//b往c倒insert(a, b - min(b, C- c), min(c + b, C));//c往a倒insert(min(a + c, A), b, c - min(c, A - a));//c往b倒insert(a, min(b + c, B), c - min(c, B - b));}}int main(){cin>>A>>B>>C;bfs();for(int c=0;c<=C;c++){if(vis[0][C-c][c]) cout<<c<<" ";}}