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的更多相关文章

  1. hdu3599 War(最大流)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud War Time Limit: 2000/1000 MS (Java/Others ...

  2. War(最短路+最大流)

    War http://acm.hdu.edu.cn/showproblem.php?pid=3599 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  3. 渡轮问题Ship

    题目描述 Palmia河从东往西流过Palmia国,把整个国家分成南北两半.河的两岸各有N个城市,北岸的每一个城市都与南岸的一个城市互为友好城市,而且任意两个北岸城市的友好城市都不相同.每一对友好城市 ...

  4. routes.rb和link_to的一些规则

    rails文档中描述了一个知识,link_to方法用于产生链接,但链接是根据routes.rb中的路由规则来产生的.这又分为面向资源和非面向资源两种产生链接的方法.比如 routes.rb文件中有两条 ...

  5. 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. 船靠岸边总是安全的,但那不是建造它的目的.

  6. Python requests 为pfsense 添加Routes

    # !/usr/bin/python 2 # -*- coding: utf-8 -*- __author__ = "Evilxr" import requests ips = o ...

  7. Rails ---> routes.rb 详解

    理解路由的目的 看懂routes.rb文件中的代码 使用经典的hash风格或者现在比较流行的Restful风格构造你自己的路径 断定一个路径会映射到哪一个controller和action 路由的双重 ...

  8. [转]学习Nop中Routes的使用

    本文转自:http://www.cnblogs.com/miku/archive/2012/09/27/2706276.html 1. 映射路由 大型MVC项目为了扩展性,可维护性不能像一般项目在Gl ...

  9. XidianOJ 1176 ship

    题目描述 The members of XDU-ACM group went camp this summer holiday. They came across a river one day. T ...

随机推荐

  1. SQL2005中的事务与锁定(五)- 转载

    ------------------------------------------------------------------------ -- Author : HappyFlyStone - ...

  2. 编译boost

    参数意义: --build-dir:  编译的临时文件会放在builddir里(这样比较好管理,编译完就可以把它删除了) --stagedir:  存放编译后库文件的路径,默认是stage --bui ...

  3. es5.0 head插件安装

    1. 在 elasticsearch.yml 文件增加配置http.cors.enabled: truehttp.cors.allow-origin: "*"2. 下载插件git ...

  4. Linux 中断详解 【转】

    转自:http://blog.csdn.net/tiangwan2011/article/details/7891818 原文地址 http://www.yesky.com/20010813/1921 ...

  5. [转]Win7 64位搭建本地SVN服务器 Apache+Subversion

    转载地址:http://blog.sina.com.cn/s/blog_4f072a7001015j5z.html 一.工具下载 01.SVN 服务器Subversion:Setup-Subversi ...

  6. Linux 打通ssh无密码登录

    像hadoop和spark这类的集群,因为master节点要控制slave节点,以及各节点之间要交互信息,所以需要各节点之间能够互相无密码登录. 通过RSA保存密码, 基本操作如下: Step 1: ...

  7. HDU 5686:2016"百度之星" - 资格赛 Problem B

    原文链接:https://www.dreamwings.cn/hdu5686/2645.html Problem B Time Limit: 2000/1000 MS (Java/Others)    ...

  8. Shell.xaml

    <Window x:Class="HelloWorld.Shell" xmlns="http://schemas.microsoft.com/winfx/2006/ ...

  9. selenium高亮显示操作步骤方法

    package com.allin.pc;import java.util.List;import org.openqa.selenium.WebElement;import org.openqa.s ...

  10. 【前端】String.prototype.match() 用法详解

    var str="1 plus 2 equal 3" // 正则表达式 console.log(str.match(/\d+/g)); // ["1", &qu ...