Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: codeKNIGHT
- LANG: JAVA
- TASK: milk3
- */
- import java.util.*;
- import java.math.*;
- import java.io.*;
- class milk3
- {
- static int cap[]=new int[3];
- static boolean visit[];
- static int dp[][];
- public static void main(String args[])throws IOException
- {
- Scanner in=new Scanner(System.in);
- //Scanner in=new Scanner(new FileReader("milk3.in"));
- PrintWriter out=new PrintWriter(System.out);
- //BufferedReader br=new BufferedReader(new FileReader("C:\\Users\\Lokesh\\Desktop\\input.in"));
- //PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("milk3.out")));
- int i;
- for(i=0;i<3;i++)
- cap[i]=in.nextInt();
- dp=new int[cap[0]+1][cap[1]+1];
- visit=new boolean[cap[2]+1];
- int k[]=new int[]{0,0,cap[2]};
- search(k);
- StringBuilder res=new StringBuilder("");
- for(i=0;i<=cap[2];i++)
- if(visit[i])
- res.append(i+" ");
- String ans=res.toString();
- ans=ans.trim();
- out.println(ans);
- out.flush();
- System.exit(0);
- }
- public static void search(int cur[])
- {
- if(dp[cur[0]][cur[1]]==1)
- return;
- dp[cur[0]][cur[1]]=1;
- if(cur[0]==0)
- visit[cur[2]]=true;
- int i,j;
- for(i=0;i<3;i++)
- {
- for(j=0;j<3;j++)
- {
- if(i!=j)
- {
- int temp[]={cur[0],cur[1],cur[2]};
- int a[]=pour(cur,i,j);
- if(dp[a[0]][a[1]]==0)
- search(a);
- cur=temp;
- }
- }
- }
- }
- public static int [] pour(int c[],int from,int to)
- {
- int amt=c[from];
- if(c[to]+amt>cap[to])
- amt=cap[to]-c[to];
- c[to]+=amt;
- c[from]-=amt;
- return c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement