[topcoder]UnsealTheSafe
http://community.topcoder.com/stat?c=problem_statement&pm=4471&rd=10711
这题果然是道简单题,图+DP。拿道题便觉得可以用邻接表表示,然后想要找所有的,是不是要BFS,DFS搜索/遍历?又觉得到过的节点又能回去不好算。忽然间想到每个节点都来自旁边的节点,这样就有阶段了,马上出来状态转移方程,DP得解。
public class UnsealTheSafe
{
public long countPasswords(int N)
{
int[][] G = new int[10][];
G[0] = new int[]{7};
G[1] = new int[]{2, 4};
G[2] = new int[]{1, 3, 5};
G[3] = new int[]{2, 6};
G[4] = new int[]{1, 5, 7};
G[5] = new int[]{2, 4, 6, 8};
G[6] = new int[]{3, 5, 9};
G[7] = new int[]{4, 8, 0};
G[8] = new int[]{5, 7, 9};
G[9] = new int[]{6, 8}; long[][] DP = new long[10][30];
for (int i = 0; i < 10; i++)
{
DP[i][1] = 1;
}
for (int i = 2; i <= N; i++)
{
for (int j = 0; j < 10; j++)
{
for (int k = 0; k < G[j].length; k++)
{
DP[j][i] += DP[G[j][k]][i-1];
}
}
}
long sum = 0;
for (int i = 0; i < 10; i++)
{
sum += DP[i][N];
}
return sum;
}
}
[topcoder]UnsealTheSafe的更多相关文章
- TopCoder kawigiEdit插件配置
kawigiEdit插件可以提高 TopCoder编译,提交效率,可以管理保存每次SRM的代码. kawigiEdit下载地址:http://code.google.com/p/kawigiedit/ ...
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- TopCoder比赛总结表
TopCoder 250 500 ...
- Topcoder几例C++字符串应用
本文写于9月初,是利用Topcoder准备应聘时的机试环节临时补习的C++的一部分内容.签约之后,没有再进行练习,此文暂告一段落. 换句话说,就是本文太监了,一直做草稿看着别扭,删掉又觉得可惜,索性发 ...
- TopCoder
在TopCoder下载好luncher,网址:https://www.topcoder.com/community/competitive%20programming/ 选择launch web ar ...
- TopCoder SRM 596 DIV 1 250
body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...
- 求拓扑排序的数量,例题 topcoder srm 654 div2 500
周赛时遇到的一道比较有意思的题目: Problem Statement There are N rooms in Maki's new house. The rooms are number ...
- TopCoder SRM 590
第一次做TC,不太习惯,各种调试,只做了一题...... Problem Statement Fox Ciel is going to play Gomoku with her friend ...
- Topcoder Arena插件配置和训练指南
一. Arena插件配置 1. 下载Arena 指针:http://community.topcoder.com/tc?module=MyHome 左边Competitions->Algorit ...
随机推荐
- java 对象的this使用 java方法中参数传递特性 方法的递归
一.this关键字,使用的情形,以及如何使用. 1.使用的情形 类中的方法体中使用this --初始化该对象 类的构造器中使用this --引用,调用该方法的对象 2.不写this,调用 只要方法或 ...
- hdu2025java字符题
查找最大元素 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- winows 进程通信的实例详解
发送端: 新建一个基本对话框工程,添加6个文本框控件,并且关联控件变量(CString类型): m_strCopyData, m_strFileMap, m_strMem, m_strRegMsg, ...
- Java基础知识强化之IO流笔记25:FileInputStream / FileOutputStream 复制图片案例
1. 需求:把D:\\美女.jpg 复制到当前项目目录下mn.jpg 代码示例: package com.himi.filecopy; import java.io.FileInputStream; ...
- System Operations on AWS - Lab 1W - Creating EC2 (Windows)
1. 创建CommandHost实例,登录到CommandHost,通过AWS CLI创建WebServer实例. 1.1 为CommandHost实例创建一个IAM角色 1.2 创建CommandH ...
- Plain old data structure(POD)
Plain old data structure, 缩写为POD, 是C++语言的标准中定义的一类数据结构,POD适用于需要明确的数据底层操作的系统中.POD通常被用在系统的边界处,即指不同系统之间只 ...
- android下4G上网卡
架构: APP Call Trachker/SMS Dispatch/Service Tracker/Data Tracker ------------------------------------ ...
- HDU-1012(水题)
http://acm.hdu.edu.cn/showproblem.php?pid=1012 分析:就按题目给的公式一步步输出就行了. #include<stdio.h> #include ...
- 自己写的SqlHelper
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- (转)VS自带工具:dumpbin的使用
有时候我们想查看一个exe引用了哪些动态库,或者我们想看某个动态库包含哪些接口函数,这个时候可以使用dumpbin.exe工具: 1.输入Dumpbin -imports calldll.exe查看它 ...