BZOJ 4005 [Jloi 2015] lie to me.

Source: Internet
Author: User

First, we can get: the number of each row is different, so each row will have and only one in $[0, m]$ number does not appear.

We can consider setting the $Dp [i][j]$ for processing the countdown $i $ line, the penultimate $i $ line missing number is $j $ of the scheme number.

Then there are:

$ $Dp [I][j] = \sum_{k=max (0,j-1)}^{m}dp[i-1][k]$$

Draw a drawing on your own to understand, here does not explain. After all, Gromah is too lazy ($ru \grave{o}$)

And then we thought about moving this picture out:

Then it's the number of path bars from top left to bottom right in this figure. (only left or right or down at a time)

Conversion, in fact, is to ask for this thing:

From $ (0,0) $ to $ (n*2+m+1,m+1) $, each time you can $x +1,y-1$ or $x +1,y+1$, and do not pass through $y =0$ and $y =m+1$ the number of path bars for both lines.

First, the complete works are ${n*2+m+1 \choose m+1}$,

Then we count the number of paths through the $y =0$, since through $y =0$ must pass through the $y =-1$, so we let the end and $y =m+2$ this line along $y =-1$,

You can then calculate the number of path bars (0,0) $ to the end of the rollover.

So it's not over yet. And those paths that go through $y =0$ and then through $y =m+1$ this straight line we're going to add back ...

It then flips the coordinate system along the $y =m+2$ (which should be $y =-m-4$) after flipping. Then the answer to the statistics ...

Until the scheme is $0$.

Calculate the number of path strips passing through the $y =m+1$ ...

I know my language ability and low, so the code is good ...

1#include <cmath>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7typedefLong LongLL;8 #defineN 30000009 #defineMod 1000000007Ten  One intN, m, ans =0; A intFac[n +1], Inv[n +1]; -  -InlineintPowerintUintv) the { -     intres =1; -      for(; v; v >>=1) -     { +         if(V &1) res = (LL) res * U%Mod; -U = (LL) u * U%Mod; +     } A     returnRes; at } -  -InlinevoidPrepare () - { -fac[0] = inv[0] =1; -      for(inti =1; I <= N; i + +) inFac[i] = (LL) fac[i-1] * I%Mod; -Inv[n] = Power (fac[n), Mod-2); to      for(inti = N-1; I I--) +Inv[i] = (LL) Inv[i +1] * (i +1) %Mod; - } the  *InlineintCintUintv) $ {Panax Notoginseng     if(U <0|| V <0|| U < v)return 0; -     return(LL) fac[u] * Inv[v]% Mod * Inv[u-v]%Mod; the } +  AInlineintTintUintv) the { +     if(U < ABS (v))return 0; -     returnC (U, u-abs (v) >>1); $ } $  -InlineintINC (intUintv) - { the     returnU + V-(U + v >= Mod?) Mod:0); - }Wuyi  the intMain () - { Wu #ifndef Online_judge -Freopen ("4005.in","R", stdin); AboutFreopen ("4005.out","W", stdout); $     #endif -      - Prepare (); -scanf"%d%d", &n, &m); A     intx = n *2+ M +1; +Ans = T (x, M +1); the      -      for(inty = m +1, y_1 =-1, y_2 = m +2; X >=abs (y);) $     { they =2* Y_1-y; theY_2 =2* Y_1-y_2; theAns = Inc (ans, Mod-T (x, y)); they =2* Y_2-y; -Y_1 =2* Y_2-y_1; inAns =Inc (ans, T (x, y)); the     } the      About      for(inty = m +1, y_1 = m +2, y_2 =-1; X >=abs (y);) the     { they =2* Y_1-y; theY_2 =2* Y_1-y_2; +Ans = Inc (ans, Mod-T (x, y)); -y =2* Y_2-y; theY_1 =2* Y_2-y_1;BayiAns =Inc (ans, T (x, y)); the     } the      -printf"%d\n", ans); -      the #ifndef Online_judge the fclose (stdin); the fclose (stdout); the     #endif -     return 0; the}
4005_gromah

Bzoj 4005 [jloi 2015] cheat me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.