| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
不知道为什么,这个算法可以过。(付Java代码),求大神解释一下原因。谢谢 import java.util.*;
public class Poj1579 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a,b,c;
while(true) {
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
if(a==-1 && b ==-1 && c == -1)
break;
System.out.println("w("+a+", "+b+", "+c+") = " + w(a,b,c));
}
sc.close();
}
//w
public static long w(int a,int b,int c) {
if(a <= 0|| b <= 0 || c <= 0)
return 1;
if(a > 20 || b > 20 || c > 20)
return w(20,20,20);
if(a <=b|| a<=c) {
//System.out.println(w(a,b,c-1) +" "+ w(a,b-1,c-1) + " " + -w(a,b-1,c));
//return w(a,b,c-1) + w(a,b-1,c-1) -w(a,b-1,c);
return (long)Math.pow(2,a);
}
//System.out.println(w(a-1,b,c)+" " + w(a-1,b-1,c)+ " " +w(a-1,b,c-1)+ " " +-w(a-1,b-1,c-1));
return w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator