import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner; public class Main {
private static Scanner cin;
private static HashMap<String, Integer> map = new HashMap<String, Integer>(); public static void main(String args[]) throws Exception {
cin = new Scanner(System.in);
boolean loop = true;
int a = 0;
int b = 0;
int c = 0;
//为了减少IO等待时间,先把数据读取进来存储到List
LinkedList<TripleInteger> list = new LinkedList<TripleInteger>();
while(loop) {
a = cin.nextInt();
b = cin.nextInt();
c = cin.nextInt();
if(-1==a && -1==b && -1==c) {
loop = false;
}else {
list.add(new TripleInteger(a,b,c));
}
} Iterator<TripleInteger> it = list.iterator();
while(it.hasNext()) {
TripleInteger ti = it.next();
System.out.println(String.format("w(%d, %d, %d) = %d", ti.getA(),ti.getB(),ti.getC(),calc(ti.getA(),ti.getB(),ti.getC())));
}
} public static int calc(int a, int b, int c) {
int ret = 1; if( a<=0 || b<=0 || c<=0) {
return ret;
}else if(a>20 || b>20 || c>20){
ret = calc(20,20,20);
}else if(map.containsKey(String.format("%d-%d-%d", a,b,c))) {
return (Integer)map.get(String.format("%d-%d-%d", a,b,c));
}
//如果a<b并且b<c 就返回w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c)
else if(a<b && b<c) {
ret = calc(a,b,c-1)+calc(a,b-1,c-1)-calc(a,b-1,c);
map.put(String.format("%d-%d-%d", a,b,c), ret);
}
//w(a−1,b,c)+w(a−1,b−1,c)+w(a−1,b,c−1)−w(a−1,b−1,c−1)
else {
ret = calc(a-1,b,c)+calc(a-1,b-1,c)+calc(a-1,b,c-1)-calc(a-1,b-1,c-1);
map.put(String.format("%d-%d-%d", a,b,c), ret);
}
return ret;
} } final class TripleInteger{
int a;
int b;
int c; public TripleInteger(int a,int b,int c) {
this.a = a;
this.b = b;
this.c = c;
}
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public int getB() {
return b;
}
public void setB(int b) {
this.b = b;
}
public int getC() {
return c;
}
public void setC(int c) {
this.c = c;
} }

java实现 洛谷 P1464 Function的更多相关文章

  1. 洛谷P1464 Function  HDU P1579 Function Run Fun

    洛谷P1464 Function HDU P1579 Function Run Fun 题目描述 对于一个递归函数w(a,b,c) 如果a≤0 or b≤0 or c≤0就返回值11. 如果a> ...

  2. (水题)洛谷 - P1464 - Function

    https://www.luogu.org/problemnew/show/P1464 #include<bits/stdc++.h> using namespace std; #defi ...

  3. 洛谷 P1464 Function【记忆化搜索】

    题目链接 题目描述 对于一个递归函数w(a,b,c) 如果a<=0 or b<=0 or c<=0就返回值1. 如果a>20 or b>20 or c>20就返回w ...

  4. 洛谷 P1464 Function【动态规划(递推)/记忆化搜索(递归)】

    题目描述 对于一个递归函数w(a,b,c) 如果a<=0 or b<=0 or c<=0就返回值1. 如果a>20 or b>20 or c>20就返回w(20,2 ...

  5. 洛谷 P1464 Function

    题目描述 对于一个递归函数w(a,b,c) 如果a<=0 or b<=0 or c<=0就返回值1. 如果a>20 or b>20 or c>20就返回w(20,2 ...

  6. 洛谷P1464 Function

    对于一个递归函数w(a,b,c)w(a,b,c) 如果a \le 0a≤0 or b \le 0b≤0 or c \le 0c≤0就返回值11. 如果a>20a>20 or b>20 ...

  7. 【做题笔记】洛谷P1464 Function

    我先谔谔一波 /kk 我谔谔 看题第一眼:欸这不就是按题意递归嘛,,直接搞不就好了 3 min 后,重新看题 然后自己手玩了几个样例,噢,递归太多了,铁定会 T 啊...... 然后,作为一个从没写过 ...

  8. 洛谷 P1464 Function(简单记忆化)

    嗯... 让一切从水开始吧... 水过初赛,但愿复赛能够接着水过... 这道题不记忆化会tle,所以用空间换时间,将每次的答案(只有20*20*20个)存下来,如果之前已经求过,就不需要重复求了... ...

  9. Java实现 洛谷 Car的旅行路线

    输入输出样例 输入样例#1: 1 3 10 1 3 1 1 1 3 3 1 30 2 5 7 4 5 2 1 8 6 8 8 11 6 3 输出样例#1: 47.5 import java.util. ...

随机推荐

  1. Spring Cloud 系列之 Bus 消息总线

    什么是消息总线 消息代理中间件构建一个共用的消息主题让所有微服务实例订阅,当该消息主题产生消息时会被所有微服务实例监听和消费. 消息代理又是什么?消息代理是一个消息验证.传输.路由的架构模式,主要用来 ...

  2. Spring全家桶之spring boot(一)

    spring boot框架抛弃了繁琐的xml配置过程,采用大量的默认配置简化我们的开发过程.使用spring boot之后就不用像以前使用ssm的时候添加那么多配置文件了,spring boot除了支 ...

  3. zsy后台管理系统-架构设计

    Zsy框架总体架构设计 1.Mysql数据库,存储所有表的数据. 2.Zsy-基础项目(Zsy-Model,Zsy-Dao,Zsy-Service,Zsy-Web),基于SSM框架.项目功能包含基本的 ...

  4. 我们为什么推荐在Json中使用string表示Number属性值?

    在这篇简短的文章中,我将解释在使用JSON传输数据时,为什么浮点数或大十进制值应表示为字符串 . long类型引发的诡异情况 长话短说,同事在利用swagger对接后端API时,诡异的发现swagge ...

  5. 「雕爷学编程」Arduino动手做(26)——4X4矩阵键盘模块

    37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里 ...

  6. MySQL zip解压 安装过程和配置

    MYSQL官网下载地址:https://dev.mysql.com/downloads/mysql/   1.下载mysql-5.7.19-winx64.zip,解压到指定的文件夹, 例如:E:\so ...

  7. JDK 安装与环境变量配置

    JDK官网下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 1.下载jd ...

  8. python3.x 基础六:面向对象

    面向对象特性 class 类 一个类是对一类拥有相同属性的对象的描述,在类中定义了这些对象都具备的属性/共同方法 object对象 一个对象指一个类实例化后的实例,一个类必须经过实例化后才能在程序中调 ...

  9. CF918C The Monster

    题目链接:http://codeforces.com/contest/918/problem/C 知识点: 贪心 解题思路: 枚举起点(当起点就是\(')'\)时直接跳过)并在此基础上遍历字符串,用一 ...

  10. Java——反射三种方式的效率对比

    转载自:https://blog.csdn.net/aitcax/article/details/52694423 1 使用field(效率最高)             long start = S ...