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. 如何搭建一个WEB服务器项目(六)—— 上传图片至服务器

    上传图片(用户头像)至服务器 观前提示:本系列文章有关服务器以及后端程序这些概念,我写的全是自己的理解,并不一定正确,希望不要误人子弟.欢迎各位大佬来评论区提出问题或者是指出错误,分享宝贵经验.先谢谢 ...

  2. AIRAC

    AIRAC是国际上划定的,以28天为一个周期的航行资料定期生效制. 2020年比较特殊,共有14个周期,分别是: 2001 2020/01/02 2020/01/29 2002 2020/01/30 ...

  3. clickhouse入门到实战及面试

    第一章. clickhouse入门 一.ClickHouse介绍 ClickHouse(开源)是一个面向列的数据库管理系统(DBMS),用于在线分析处理查询(OLAP). 关键词:开源.面向列.联机分 ...

  4. git init 后关联github仓库是发生错误:

    : failed to push some refs to 'git@github.com:AlanKnightly/reactC.git'hint: Updates were rejected be ...

  5. vue钩子

    全局钩子 const router = new VueRouter({ ... }) router.beforeEach((to, from, next) => { // ... }) 钩子是异 ...

  6. 剑指Offer02之替换空格

    剑指Offer02之替换空格 题目描述 实现一个方法,将输入的字符串中的空格替换成%20. 例子如下 hello world --> hello%20world 代码实现 //方法一 采用Jav ...

  7. 流复制-pg_start_backup(带自定义表空间)

    一.准备slave库 archive_mode = on ---开启归档模式 archive_command = 'test ! -f /mysqldata/pg/archive_active/%f ...

  8. Java——字符串排序

    import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Test { ...

  9. Element-UI自定义主题

    Element-UI自定义主题 1.介绍:我们可以自定义样式去覆盖element-ui的默认样式 // 在项目目录中新建 element-variables.scss 文件 // 上面为修改的变量 $ ...

  10. 基于 abp vNext 和 .NET Core 开发博客项目 - 使用Redis缓存数据

    上一篇文章(https://www.cnblogs.com/meowv/p/12943699.html)完成了项目的全局异常处理和日志记录. 在日志记录中使用的静态方法有人指出写法不是很优雅,遂优化一 ...