USACO中的搜索
2014-03-12 15:40
351 查看
Mother's Milk
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;
const int n = 25;
int flag
;
int re
;
int A,B,C;
void DFS(int a,int b,int c)
{
if(a == 0)
re[c] = 1;
if(flag[a][b]) return;
flag[a][b] = 1;
if(a>0 && b<B) //A向B倒, c不变
DFS(max(0, a+b-B), min(B, a+b), c);
if(a>0 && c<C) //A向C倒,b不变
DFS(max(0, a+c-C), b, min(C, a+c));
if(b>0 && a<A) //B向A倒,c不变
DFS(min(A, a+b), max(0, b+a-A), c);
if(b>0 && c<C) //B向C倒,a不变
DFS(a, max(0, b+c-C), min(C, b+c));
if(c>0 && a<A) //C向A倒,b不变
DFS(min(A, a+c), b, max(0, a+c-A));
if(c>0 && b<B) //C向B倒,a不变
DFS(a, min(B, b+c), max(0, b+c-B));
}
int main()
{
freopen("milk3.in","r",stdin);
freopen("milk3.out","w",stdout);
cin>>A>>B>>C;
memset(flag,0,sizeof(flag));
memset(re,0,sizeof(re));
DFS(0,0,C);
for(int i = 0; i < C; i++)
{
if(re[i])
cout<<i<<" ";
}
cout<<C<<endl;
return 0;
}
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;
const int n = 25;
int flag
;
int re
;
int A,B,C;
void DFS(int a,int b,int c)
{
if(a == 0)
re[c] = 1;
if(flag[a][b]) return;
flag[a][b] = 1;
if(a>0 && b<B) //A向B倒, c不变
DFS(max(0, a+b-B), min(B, a+b), c);
if(a>0 && c<C) //A向C倒,b不变
DFS(max(0, a+c-C), b, min(C, a+c));
if(b>0 && a<A) //B向A倒,c不变
DFS(min(A, a+b), max(0, b+a-A), c);
if(b>0 && c<C) //B向C倒,a不变
DFS(a, max(0, b+c-C), min(C, b+c));
if(c>0 && a<A) //C向A倒,b不变
DFS(min(A, a+c), b, max(0, a+c-A));
if(c>0 && b<B) //C向B倒,a不变
DFS(a, min(B, b+c), max(0, b+c-B));
}
int main()
{
freopen("milk3.in","r",stdin);
freopen("milk3.out","w",stdout);
cin>>A>>B>>C;
memset(flag,0,sizeof(flag));
memset(re,0,sizeof(re));
DFS(0,0,C);
for(int i = 0; i < C; i++)
{
if(re[i])
cout<<i<<" ";
}
cout<<C<<endl;
return 0;
}
相关文章推荐
- 【搜索】【USACO】Checker Challenge
- CodeVS 1416|USACO Train 5.5.3|Two Five|二五语言|搜索
- 1751: [Usaco2005 qua]Lake Counting (搜索)
- BZOJ 1770: [Usaco2009 Nov]lights 燈 [高斯消元XOR 搜索]
- |BZOJ 1619|搜索|[Usaco2008 Nov]Guarding the Farm 保卫牧场
- HDOJ 4277 USACO ORZ 搜索+剪枝
- [搜索]USACO-1.5-Prime Palindromes
- 【搜索】洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace
- 【搜索】洛谷 P1215 [USACO1.4]母亲的牛奶 Mother's Milk
- 【USACO3.1.3】丑数 恶心搜索题
- 08-26 HDU3812 HDU3816 USACO 4.2~4.3 搜索剪枝,模拟,DP
- USACO-Section2.1 Healthy Holsteins [搜索][枚举]
- USACO-Section3.3 Camelot【宽度优先搜索】
- USACO 1.4 Arithmetic Progressions (暴力搜索)
- 状态压缩搜索——【USACO2.2.4】派对灯
- POJ - 2456/USACO - Feb05 Gold Aggressive cows 二分搜索+区间选点+贪心
- 【搜索】【USACO】Overfencing
- 折半搜索+状态压缩【P3067】 [USACO12OPEN]平衡的奶牛群Balanced Cow S…
- USACO-Section1.3 Wormholes [搜索]
- usaco 4.1 Beef McNuggets 搜索