1172. Ship Routes
http://acm.timus.ru/problem.aspx?space=1&num=1172
水题DP 大整数直接上java
代码:
import java.math.BigInteger;
import java.util.Scanner; public class Main { /**
* @param args
*/
static final int N = 35; public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
BigInteger[][][][] dp = new BigInteger[N][N][N][4];
int n = in.nextInt();
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
for (int l = 0; l <= n; ++l) {
for (int k = 1; k <= 3; ++k) {
dp[i][j][l][k]=BigInteger.ZERO;
}
}
}
}
dp[0][0][0][1] = BigInteger.ONE;
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
for (int l = 0; l <= n; ++l) {
for (int k = 1; k <= 3; ++k) {
if (dp[i][j][l][k].compareTo(BigInteger.ZERO) == 1) {
if (k != 1 && i < n) {
dp[i + 1][j][l][1] = dp[i + 1][j][l][1]
.add(dp[i][j][l][k].multiply(BigInteger
.valueOf(Math.max(1, n - i - 1))));
}
if (k != 2 && j < n) {
dp[i][j + 1][l][2] = dp[i][j + 1][l][2]
.add(dp[i][j][l][k].multiply(BigInteger
.valueOf(n - j)));
}
if (k != 3 && l < n) {
dp[i][j][l + 1][3] = dp[i][j][l + 1][3]
.add(dp[i][j][l][k].multiply(BigInteger
.valueOf(n - l)));
}
}
}
}
}
}
System.out.println(dp[n][n][n][1].divide(BigInteger.valueOf(2L)));
} }
1172. Ship Routes的更多相关文章
- hdu3599 War(最大流)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud War Time Limit: 2000/1000 MS (Java/Others ...
- War(最短路+最大流)
War http://acm.hdu.edu.cn/showproblem.php?pid=3599 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 渡轮问题Ship
题目描述 Palmia河从东往西流过Palmia国,把整个国家分成南北两半.河的两岸各有N个城市,北岸的每一个城市都与南岸的一个城市互为友好城市,而且任意两个北岸城市的友好城市都不相同.每一对友好城市 ...
- routes.rb和link_to的一些规则
rails文档中描述了一个知识,link_to方法用于产生链接,但链接是根据routes.rb中的路由规则来产生的.这又分为面向资源和非面向资源两种产生链接的方法.比如 routes.rb文件中有两条 ...
- A ship is always safe at the shore - but that is not what it is built for.
A ship is always safe at the shore - but that is not what it is built for. 船靠岸边总是安全的,但那不是建造它的目的.
- Python requests 为pfsense 添加Routes
# !/usr/bin/python 2 # -*- coding: utf-8 -*- __author__ = "Evilxr" import requests ips = o ...
- Rails ---> routes.rb 详解
理解路由的目的 看懂routes.rb文件中的代码 使用经典的hash风格或者现在比较流行的Restful风格构造你自己的路径 断定一个路径会映射到哪一个controller和action 路由的双重 ...
- [转]学习Nop中Routes的使用
本文转自:http://www.cnblogs.com/miku/archive/2012/09/27/2706276.html 1. 映射路由 大型MVC项目为了扩展性,可维护性不能像一般项目在Gl ...
- XidianOJ 1176 ship
题目描述 The members of XDU-ACM group went camp this summer holiday. They came across a river one day. T ...
随机推荐
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数005·graphics-obj,基本绘图单元,包括线段、矩形、椭圆、圆形
<zw版·Halcon-delphi系列原创教程> Halcon分类函数005·graphics-obj,基本绘图单元,包括线段.矩形.椭圆.圆形 graphics-obj,基本绘图单元, ...
- Spring aop报错:com.sun.proxy.$Proxy cannot be cast to xxx
准备使用AOP记录所有NamedParameterJdbcTemplate操作数据时的所有日志,没想到出现这个错误,折腾了好久,终于找出原因 解决方案:在 aop-config配置添加上: proxy ...
- UICollectionViewDelegateFlowLayout 使用
import UIKit //UICollectionViewLayout //itemSize属性 //设定全局的Cell尺寸,如果想要单独定义某个Cell的尺寸,可以使用下面方法: // - (C ...
- Hadoop之hive的drop table恢复
一.引言: 快下班的时候我开发同事问能不能将hive中drop掉的数据恢复过来,我记得是有开回收站的,当时我回答说可以恢复的. 二.恢复过程: 在之前我有对hadoop的回收站有过了解,就是将hdfs ...
- hash命令
什么是hash ? 在网上找了好久都没找到简截有力的说明.hash 我把它当成是集合,一个hash 就是一个集合,里面字段对应一个元素,元素不重复,字段都不一样. 简单hash 命令 1.hset 哈 ...
- laravel框架总结(六) -- 门面(facades)
Facades 为应用程序的服务容器中可用的类提供了一个「静态」接口. Laravel 本身附带许多的 facades,甚至你可能在不知情的状况下已经在使用他们! xpower的静态接口(门面 ...
- logging模块转载博客
转载自:http://blog.csdn.net/zyz511919766/article/details/25136485 简单将日志打印到屏幕: [python] view plain copy ...
- Python namedtuple
我们都知道Python中的tuple是一个非常高效的集合对象,但是我们只能通过索引的方式访问这个集合中的元素,比如下面的代码: Bob=('bob',30,'male') print'Represen ...
- centos 服务开机启动设置
建立服务文件以nginx 为例 vim /lib/systemd/system/nginx.service 在nginx.service 中插入一下内容 [Unit] Description=ngin ...
- String和string的区别
(1)从位置讲 1.string是c#中的的 2.String是 .Net Framework的一个函数名(类),基于using.System的引用 (2)从性质讲 1.string是关键字,Stri ...