Swust OJ 2516 coach I want to learn arithmetic dp+ combination count

Source: Internet
Author: User

#include <stdio.h> #include <string.h> #include <iostream> #include <string> #include <queue > #include <cmath> #include <map> #include <algorithm> #include <vector>//#define Debugusing namespace Std;const int inf = 0x3fffffff;const int mod = 1000000007;const int mmax = 1000010;typedef long Long ll;int n,m K LL Inv[mmax]; LL Jie[mmax];    LL dp[1100];void Pre () {inv[0]=inv[1]=1;    Jie[0]=jie[1]=1;        for (int i=2;i<mmax;i++) {inv[i]= (LL) (mod-mod/i) *inv[mod%i]%mod;        Jie[i]=jie[i-1]*i;    Jie[i]%=mod;        } for (int i=2;i<mmax;i++) {inv[i]*=inv[i-1];    Inv[i]%=mod;    }}ll Pow_mod (ll x, int n) {ll res=1,tmp=x;        for (; n;n/=2) {if (n&1) res= (res*tmp)%mod;    tmp= (tmp*tmp)%mod; } return res;    LL C (int x,int y) {if (y>x) return 0; return jie[x]*inv[y]%mod*inv[x-y]%mod;}    void Build () {dp[0]=0;    Dp[1]=1; for (int i=2;i<=n;i++) {Dp[i]=pow_mod (I,n);            for (int j=1;j<i;j++) {dp[i]-=dp[i-j]*c (i,j)%mod;        dp[i]= (dp[i]%mod+mod)%mod;    }}}int Main () {pre ();            while (~SCANF ("%d%d%d", &n,&m,&k)) {if (m==1) {printf ("%lld\n", Pow_mod (K,n));        Continue        } build ();        LL cnt=0;                for (int i=0;i<=n;i++) {for (int j=0;i+j<=n;j++) {LL tmp=1;                Tmp=c (k,i) *c (k-i,j)%mod*c (k-i-j,j)%mod;                Tmp*=dp[i+j]*dp[i+j]%mod*pow_mod (LL) i,n* (m-2))%mod;                Tmp%=mod;                cnt+=tmp;            Cnt%=mod;    }} printf ("%lld\n", CNT); } return 0;}

Swust OJ 2516 coach I want to learn arithmetic dp+ combination count

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.