Codeforces 57C array DP brute force detection rules

Source: Internet
Author: User

Question link: Click the open link

First, the non-incremental computing solution,

If the number of non-incrementing solutions is X, the number of non-incrementing solutions is X

The answer is 2 X-n.

You only need to obtain X.

You can write a N3 DP first, and then find that the rule is C (n-1, 2 * N-1)

Set a reverse element.

#include<iostream>#include<cstdio>#include<vector>#include<string.h>using namespace std;#define ll long long#define mod 1000000007ll n;ll Pow(ll x, ll y){    ll ans = 1;    while(y)    {        if(y&1) ans = (ans * x) % mod;        y >>= 1;        x = (x*x)%mod;    }    return ans;}ll chu(ll x, ll y){    return (x * Pow(y, mod-2))%mod;}int main(){ll i, j;while(cin>>n){        if(n==1){puts("1");continue;}        n -- ;        ll ans = n+2;        ll zi = 2, mu = n+3;        for(i = n+3; i <= 2*n+1; i++)        {            ans *= mu;            ans = chu(ans % mod, zi);            mu++; zi++;        }        ans *= 2; ans -= (n+1);        ans += mod;        cout<<ans%mod<<endl;}return 0;}

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.