`
水木清华77
  • 浏览: 36890 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Problem15

阅读更多
package com.yao.Algorithms;

import java.util.HashMap;
import java.util.Map;
/**
 * 
 * @author shuimuqinghua77 @date 2011-11-29
 *
 */
public class Problem15 {
	private static Map<String, Node> seed = new HashMap<String, Node>();
	private static int SIZE = 20;
	private static long sum = 0;

	public static void main(String[] args) {
		seed.put(0 + ":" + 0, new Node(0, 0, 1));
		for (int i = 0; i < SIZE + SIZE; i++) {
			Map<String, Node> map = new HashMap<String, Node>();
			for (Node node : seed.values()) {
				if (node.x == SIZE || node.y == SIZE) {
					sum += node.size;
					continue;
				}
				search(node.x + 1, node.y, node.size, map);
				search(node.x, node.y + 1, node.size, map);
			}
			seed = map;
		}
		System.out.println(sum);
	}

	private static void search(int x, int y, long size, Map<String, Node> map) {
		Node node = new Node(x, y, size);
		String key = x + ":" + y;
		if (map.get(key) != null)
			map.get(key).size += size;
		else
			map.put(key, node);
	}
}

class Node {
	int x;
	int y;
	long size;

	public Node(int x, int y, long size) {
		this.x = x;
		this.y = y;
		this.size = size;
	}
}
分享到:
评论

相关推荐

    计算机网络第六版答案

    15. Google's private network connects together all its data centers, big and small. Traffic between the Google data centers passes over its private network rather than over the public Internet. Many ...

    MySQL数据库考试试题.docx

    15. 视图上的限制操作:不能定义新的基本表(Problem 15) 视图是一个基于表的虚拟表,不能在视图上定义新的基本表。 16. 子查询:嵌套查询语句(Problem 16) 子查询是指嵌套在另一个查询语句中的查询语句。 17...

    Computer-Based.Problem.Solving.Process

    Chapter 15. Software Tool Development Illustration Chapter 16. Software Tools for Correct Program Development Part 5 Computer Operation by Problem Solving Process Chapter 17. Using First Computers to...

    Inverse Problem Theory and Methods for Model Parameter Estimation

    **观测数据**:六个地震站记录了地震波到达的时间,这些地震站位于矩形网格上,坐标分别为:(3km, 15km),(3km, 16km),(4km, 15km),(4km, 16km),(5km, 15km),(5km, 16km)。地震波到达时间的观测值为:3.12秒,...

    Artificial Intelligence and Problem Solving

    Title: Artificial Intelligence and Problem Solving Author(s): Danny Kopec, Christopher Pileggi, David Ungar, Shweta Shetty Publisher: Mercury Learning & Information Year: 2017 Language: english ...

    The Orphan Problem in ZigBee Wireless Networks

    4. [Orphan problem](https://ieeexplore.ieee.org/document/4512139) - 孤儿问题的详细研究,介绍了问题的本质及其对网络性能的影响。 5. [Wireless sensor network]...

    Prime Ring Problem 深度探索

    int M, g, a[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, ag[20], c[20]; ``` - 初始化数组`a`,用于存储可能填入环中的数字。 - `ag`数组用于标记数字是否已被使用。 - `c`...

    Problem Solving with C++

    #### 第15章:继承示例(p.858) 继承是面向对象编程的核心概念之一,允许创建新的类,这些类继承现有类的属性和行为。本章提供了一个具体的继承示例。 - **基类**(父类):提供通用功能的类。 - **派生类**...

    C++.Programming.From.Problem.Analysis.to.Program.Design.7th.Edition

    Chapter 15. Recursion. Chapter 16. Searching and Sorting. Chapter 17. Linked Lists. Chapter 18. Stacks and Queues. Appendix A. Reserved Words. Appendix B. Operator Precedence. Appendix C. Character ...

    Problem Solving in Data Structures & Algorithms Using Java

    CHAPTER 15: ALGORITHM DESIGN TECHNIQUES CHAPTER 16: BRUTE FORCE ALGORITHM CHAPTER 17: GREEDY ALGORITHM CHAPTER 18: DIVIDE-AND-CONQUER, DECREASE-AND-CONQUER CHAPTER 19: DYNAMIC PROGRAMMING CHAPTER 20: ...

    Problem Solving with C++ (7th edition)

    #### Chapter 15: Inheritance This chapter focuses on inheritance, a core concept in OOP: - **Inheritance Hierarchies**: Explanation of inheritance hierarchies, including single and multiple ...

    15PuzzleProblem

    《15拼图问题》 在IT领域,15拼图问题是一个经典的组合优化问题,源于19世纪的智力玩具,通常用一个4x4的网格来表示,包含15个标有数字的小块和一个空白格。目标是通过滑动小块,使得它们按照升序排列,即1到15,...

    AN15-Power Systems for AIX III Advanced Administration and Problem Determination

    《AN15-Power Systems for AIX III Advanced Administration and Problem Determination》是一份官方培训教材,由IBM公司出版,用于指导学员进行高级系统管理以及问题诊断。这份教材通常被用于AIX操作系统环境下的...

    Problem-Solving-with-C++-9th

    #### 第15章:继承示例 - **继承**:通过具体例子展示了如何使用继承来创建子类,并讨论了基类和派生类之间的关系以及多态的概念。 #### 第16章:标准模板库异常处理 - **STL 异常类**:探讨了如何使用STL提供的...

    C++ Programming: From Problem Analysis to Program Design, 8th Edition

    C++ Programming: From Problem Analysis to Program Design By 作者: D. S. Malik ISBN-10 书号: 1337102083 ISBN-13 书号: 9781337102087 Edition 版本: 8 出版日期: 2017-02-13 pages 页数: 1491 Contents ...

    0-1-knapsack-problem-master (15)c.zip

    在压缩包"0-1-knapsack-problem-master (15)c.zip"中,可能包含了C语言实现的0-1背包问题代码示例。通过对这些代码的分析和学习,我们可以深入理解动态规划在解决此类问题中的应用,以及如何优化代码以提高运行效率...

    ProjectEulerOne:ICS 613 E15

    3. `Problem15.java` - 与欧拉问题15直接相关的类,包含了问题的解决方案。 4. `Test/` - 测试目录,包含单元测试或集成测试,用来验证代码的正确性。 5. `README.md` - 文件提供了项目简介、如何运行以及任何必要的...

Global site tag (gtag.js) - Google Analytics