Downward paths

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 844    Accepted Submission(s): 282

Problem Description
================

  Hi! I am an ACMer from CSU. This contest made by me is to celebrate my girlfriend’s birthday although the problems in this contest do not relate to her in fact. :) Any way, happy birthday to you, honey!

  Thanks to LCY, I have this chance to share my ideas and works with you. Good luck and have fun!
================
  We have a graph with size = N like that in Figure 1. Then we are going to find a downward path from the top node to one bottom node.
  First, we select the top node as the beginning. Then at any node, we can go horizontally or downward along the blue edge and reach the next node. The finding will be end when we reach one of the bottom nodes. After that we can get a downward path from the top node to one bottom node. Note that we can not pass a blue edge that we have passed ago during each finding.
  Your task is to calculate there exists how many downward paths.

 
Input
  There is an integer T (1 <= T <= 1000) in the first line, which indicates there are T test cases in total.
  For each test case, there is only one integer N (1 <= N <= 10^18) indicates the size of the graph.
 
Output
  For each test case, you should output the correct answer of the above task in one line.
  Because the answer may be very large, you should just output the remainder of it divided by 1000003.
 
Sample Input
2
1
2
 
Sample Output
2
8

Hint

  For Sample 2, the yellow paths in Figure 2 show the 8 downward paths.

 

********************************************************************************************

题意:从顶点走到底有多少条路可以走
解题思路:
    size = 1时:2*(1+0) = 2
size = 2时:2*(1+1) *2(1+0)= 8
size = 3时:2*(1+1)*2*(1+2)*2*(1+0)=48
除了最上面的顶点和最下面的点以外,size大于1时,
             1
            |    |
          2 ————3  
         |      |      |
        4————5————6
       |         |     |    |
      7————8————9————10
例如2号点可以有去4,5号点2条路,而且同时4, 5, 6这一层有2个边,4-5和5-6;
所以2号点到下一层就有2*(1+2)条路。
 
所以当size=n时,2 *(1+1)* 2 *(1+2)* 2 *(1+3) * ~~~ * 2 *(1+n-1)* 2 *(1+0)= 2^n * n!。
 
当大于1000003之后,全部n%1000003=0。
 
*********************************************************************************************
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define mset(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = +;
const int mod = ;
LL a[maxn];
int main()
{
a[] = ;
for(int i=;i<=maxn;i++)
a[i] = (a[i-] * i * )%mod;
LL T;
cin >> T;
while(T--){
LL n;
cin >> n;
if(n >= mod ){
cout << "" << endl;
continue;
}
cout << a[n] << endl;
}
return ;
}
 
 

HDU-4475 Downward paths(找规律)的更多相关文章

  1. HDU 4861 Couple doubi(找规律|费马定理)

    Couple doubi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  2. hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!

    http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE,  更重要的是找出规律后,O(n)递推也过不了,TLE,一定 ...

  3. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

  4. HDU 5703 Desert (找规律)

    题意:一杯水有n的容量,问有多少种方法可以喝完. 析:找规律,找出前几个就发现规律了,就是2的多少次幂. 代码如下: #include <cstdio> #include <stri ...

  5. hdu 4952 Number Transformation (找规律)

    题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值, ...

  6. hdu 5241 Friends(找规律?)

    Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  7. HDU 4279 Number(找规律)

    Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  8. hdu 1021 Fibonacci Again(找规律)

    http://acm.hdu.edu.cn/showproblem.php?pid=1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Others ...

  9. HDU 5963 朋友(找规律博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=5963 题意: 思路: 我们可以先只考虑单链,自己试几种案例就可以发现规律,只有与根相连的边为1时,只需要奇数次操 ...

  10. HDU 5963 朋友 (找规律,思维)

    HDU 5963 朋友 题目大意 B君在围观一群男生和一群女生玩游戏,具体来说游戏是这样的: 给出一棵n个节点的树,这棵树的每条边有一个权值,这个权值只可能是0或1. 在一局游戏开始时,会确定一个节点 ...

随机推荐

  1. Play with Chain 【HDU - 3487】【Splay+TLE讲解】

    题目链接 很好的一道题,用了三天多的时间,终于知道了我为什么T的原因,也知道了在Splay的同时该怎样子的节约时间,因为Splay本身就是大常数的O(N*logN),我们如果不在各种细节上节约时间,很 ...

  2. 5期-Metasploitable3专题课程

    metasploitable2基于ubantu的渗透演练环境.Rapid7官方长时间未更新,导致跟不上当前的节奏.metasploitable3出世. metasploitable2配合metaspl ...

  3. Mac004--Tomcat安装

    Mac--Tomcat安装 一.Tomcat下载 https://tomcat.apache.org/download-80.cgi 下载Tomcat注意tomcat与jdk版本要一致.jdk1.8版 ...

  4. sourcetree for mac 使用

    1.sourceTree clone 仓库 打开sourceTree, 点击 新仓库(1) -> 从url克隆(2), 如下图 如下图所示, 粘贴源url路径, 自动补全或者手动选择目标路径和名 ...

  5. 《JAVA设计模式》之外观模式(Facade)

    在阎宏博士的<JAVA与模式>一书中开头是这样描述门面(Facade)模式的: 门面模式是对象的结构模式,外部与一个子系统的通信必须通过一个统一的门面对象进行.门面模式提供一个高层次的接口 ...

  6. HDFS-NameNode和SeconddaryNode

    一.NN和2N的工作机制 一.概述 一.概述 一.概述 一.概述 一.概述 一.概述 一.概述

  7. webpack4.0.1的坑

    webpack4在2月底正式发布后,原来的很多做法不能使用,下面把使用webpack4.0.1过程中,出现的问题,一一记录,也欢迎大家补充,谢谢!团结就是力量,众人拾柴火焰高,加油! 关于webpac ...

  8. 《剑指offer》面试题4 替换空格 Java版

    (给一个足够长的字符数组,其中有一段字符,将' '(空格)替换成'%' '2' '0'三个字符,原字符段由'\0'结尾) 书中方法:这道题如果从头到尾扫描数组并替换,会涉及到数组的移动.如果不移动元素 ...

  9. Java 小技巧和在Java避免NullPonintException的最佳方法(翻译)

                前几天就g+里面看到有人引用这篇博文.看了一下.受益颇多. 所以翻译过来,希望和大家一起学习.本人英语水平有限,假设有错,请大家指正. 原文地址(须要翻墙):http://ja ...

  10. JavaFX程序初次运行创建数据库并执行建表SQL

    在我的第一个JavaFX程序完成安装的时候才突然发现,不能要用这个软件还要手动执行Sql来建表吧? 于是我的想法是在Main程序中执行时检测数据库连接状况,如果没有检测到数据库或者连接异常,那么出现错 ...