SW练习_ P1464 Function_记忆搜索


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class Main {
    static Map map=new HashMap<>();
    public static void main(String[] args) throws Exception{

        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        long a=0;
        long b=0;
        long c=0;
        while(true){
            StringTokenizer st=new StringTokenizer(reader.readLine());
            a=Long.parseLong(st.nextToken());
            b=Long.parseLong(st.nextToken());
            c=Long.parseLong(st.nextToken());
            if(a==-1 && b==-1 && c==-1){
                break;
            }else{
                //System.out.println(p(a,b,c));
                System.out.printf("w(%d, %d, %d) = %d \n",a,b,c,p(a,b,c));
            }
        }

        reader.close();
    }
    public static long p(long a,long b,long c){
        String key=String.valueOf(a)+"_"+String.valueOf(b)+"_"+String.valueOf(c);
        if(map.containsKey(key)){
            return map.get(key);
        }
        long v=0l;
        if(a<=0 || b<=0 || c<=0){
            v=1l;
        }else if(a>20 || b>20 || c>20){
            v=p(20,20,20);
        }else if(a

 

你可能感兴趣的:(算法)