Bzoj 4584 [Apio2016] Rowing--Dynamic planning

Source: Internet
Author: User

Subtask 1

Direct $n^2$ $DP $, it's ready.

Subtask 2

Use $f[i][j]$ to represent the current position as $i$, ending the number of scenarios for which the element is $j$.

Subtask 3

Look underneath.

Subtask 4

First, you can enumerate a sequence to select the same overlapping interval, and then some can be selected, and if so, ask for a rise.

Then it is easy to get the equation, which can be $n^4$ directly after discretization.

Then it does not optimize and look at the puzzle.

I think I can't write it.

Copy the code!

#include <map> #include <ctime> #include <cmath> #include <queue> #include <cstdio># Include <cstring> #include <iostream> #include <algorithm>using namespace std; #define F (I,j,k) for ( int i=j;i<=k;++i) #define D (I,J,K) for (int. i=j;i>=k;--i) #define LL Long Long#define MAXN 505#define MD 1000000007 in T N,b[maxn],a[maxn],siz[maxn],ls[maxn*2],top,ans=0,inv[maxn];int l[maxn],r[maxn],c[maxn],g[maxn],fac[maxn],inv_ FAC[MAXN]; int ksm (int a,int b,int p) {int ret=1;for (; b;a= (LL) a*a%p,b>>=1) if (b&1) ret= (LL) ret*a%md;return ret;} int Main ( {scanf ("%d", &n); fac[0]=1;    F (i,1,maxn-1) fac[i]= (LL) fac[i-1]*i%md; Inv_fac[0]=1;inv_fac[1]=1;    F (i,2,maxn-1) inv_fac[i]=ksm (FAC[I],MD-2,MD);    F (i,1,maxn-1) inv[i]=ksm (I,MD-2,MD);    F (i,1,n) scanf ("%d%d", &a[i],&b[i]), ls[++top]=a[i],ls[++top]=b[i]+1; Sort (ls+1,ls+top+1);    Top=unique (ls+1,ls+top+1)-ls-1;        F (i,1,n) {l[i]=lower_bound (ls+1,ls+top+1,a[i])-ls; R[i]=lower_bound (ls+1,ls+top+1,b[i]+1)-ls; } g[0]=1;    C[0]=1;        for (int j=1;j<top;++j) {int l=ls[j+1]-ls[j];        for (int i=1;i<=n;++i) c[i]= (LL) c[i-1]* (l+i-1)%md*inv[i]%md; for (int i=n;i>=1;--i) {if (L[i]<=j&&j+1<=r[i]) {int f=0,m=                1,c=l;                    for (int p=i-1;p>=0;--p) {f= (f+ (LL) c*g[p]%md)%md;                if (L[p]<=j&&j+1<=r[p]) c=c[++m];            } g[i]= (g[i]+f)%md;    }}} F (I,1,n) ans= (ans+g[i])%md; printf ("%d\n", ans);}

  

Bzoj 4584 [Apio2016] Rowing--Dynamic planning

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.