Bzoj 2024 SHOI2009 Prom Dynamic planning + principle + high precision

Source: Internet
Author: User

Topic: Given two sequence, how many matches satisfy a[i]<b[i] The logarithm does not exceed K pair

See http://blog.csdn.net/popoqqq/article/details/44514113

High precision has been wasted ...

#include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include < Algorithm> #define M 202using namespace std;struct big_int{#define BASE 1000int num[125],cnt; Big_int () {}big_int (Int _) {memset (num,0,sizeof num); num[cnt=1]=_;} big_int& operator = (Int x) {return * (new (this) big_int (x));} big_int& operator + = (const big_int &x) {Int I;cnt=max (cnt,x.cnt); for (i=1;i<=cnt;i++) {num[i]+=x.num[i];if ( num[i]>=base) Num[i+1]+=num[i]/base,num[i]%=base;} if (num[cnt+1]) ++cnt;return *this;} Big_int operator + (const big_int &x) Const{big_int Re=*this;re+=x;return re;} big_int& operator-= (const big_int &x) {Int i;for (i=1;i<=cnt;i++) {num[i]-=x.num[i];while (num[i]<0) num[ I+1]--, num[i]+=base;} while (cnt>0 &&!num[cnt])--cnt;return *this;} Big_int operator-(const big_int &x) Const{big_int Re=*this;re+=x;return re;} Friend Big_int operator * (const big_int &x,const big_int &y) {Int i,j; Big_int Re=0;for (i=1;i< =x.cnt;i++) for (j=1;j<=y.cnt;j++) re.num[i+j-1]+=x.num[i]*y.num[j];re.cnt=x.cnt+y.cnt;for (i=1;i<=re.cnt;i + +) if (re.num[i]>=base) re.num[i+1]+=re.num[i]/base,re.num[i]%=base;if (!re.num[re.cnt]) Re.cnt--;return re;} big_int& operator *= (const big_int &x) {return *this=*this*x;} Friend ostream& operator << (ostream &_,big_int &x) {Int i;printf ("%d", x.num[x.cnt]); for (i=x.cnt-1;i >0;i--) printf ("%03d", X.num[i]); return _;}} F[m][m],g[m],c[m][m],fac[m],ans;int n,k;int A[m],b[m],next[m];int Main () {int i,j;cin>>n>>k;for (i=1;i <=n;i++) scanf ("%d", &a[i]), for (i=1;i<=n;i++) scanf ("%d", &b[i]); sort (a+1,a+n+1); sort (b+1,b+n+1); (j=1,i=1;i<=n;i++) {for (; j<=n&&b[j]<=a[i];j++); next[i]=j-1;} for (i=0;i<=n;i++) {c[i][0]=1;for (j=1;j<=i;j++) c[i][j]=c[i-1][j]+c[i-1][j-1];} for (fac[0]=1,i=1;i<=n;i++) fac[i]=fac[i-1]*i;f[0][0]=1;for (i=1;i<=n;i++) {f[i][0]=1;for (j=1;j<=i;j++) f[ I][j]=f[i-1][j]+f[i-1][j-1]*max (next[i]-(j-1), 0);} for (i=n;i>=n-k;i--) {g[i]=f[n][i]*fac[n-i];for (j=i+1;j<=n;j++) g[i]-=g[j]*c[j][i];ans+=g[i];} Cout<<ans<<endl;return 0;}


Bzoj 2024 SHOI2009 Prom Dynamic planning + principle + high precision

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.