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. python 基础应用4

    1.列表所有元素全部单独输出 #所有元素全部单独输出 li = [1,2,3,'taibai',[4,5,6,'taibaia']] for i in li: if type(i) == list: ...

  2. js对页面中的内容进行拼音搜索,只对后台已经传过来的页面数据进行索引

    实现输入拼音(可以使用拼音首字母来查),来查询出已经存在于页面的数据 注意:这种写法只能适用于页面中已经存在的数据进行检索,大体意思是将本页内的数据拼接成一个字符串,然后通过该字符串去检索匹配的字符串 ...

  3. Spring 获取bean

    方法一: ApplicationContext ap = new ClassPathXmlApplicationContext("applicationContext.xml"); ...

  4. c# 贪吃蛇小游戏

    ------------恢复内容开始------------ 新手学习c# 在博客园上看到后自己模仿打出来的第一个程序  开心,纪念一下 bean :食物类 block :蛇块类 snake :蛇类 ...

  5. gulp iconfont

    参考如下网站 https://github.com/hjzheng/CUF_meeting_knowledge_share/tree/master/2015-7-24/gulp-test-iconfo ...

  6. php连接数据库 需要下载adodb

    <?include('adodb/ADOdb.inc.php'); # 加载ADODB$conn = &ADONewConnection('odbc_mssql'); # 建立一个连结$ ...

  7. (数据科学学习手札84)基于geopandas的空间数据分析——空间计算篇(上)

    本文示例代码.数据及文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 在本系列之前的文章中我们主要讨论了g ...

  8. hdu6005找带权最小环

    题意:给你点和边,让你找最小环的权值,其权值是所有边权的和,没环输出-1. 解法:枚举每一条边,找到其端点,做最短路.. #include<cstdio> #include<cstr ...

  9. Msql 给结果拼接字符串

    SELECT CONCAT("内容:",info)AS info FROM 表名;

  10. 剑指Offer之链表中倒数第k个结点

    题目描述 输入一个链表,输出该链表中倒数第k个结点.   思路:首先计算出链表的长度,再计算出倒数第k个是正数第几个,找到该结点即可. public ListNode FindKthToTail(Li ...