2017 Tsinghua computer examination - summed polynomial (polynomial)

After reading about the topic let us derive a formula it! 

 

 Push over spicy formula to analyze the complexity.

O(R(n,i)) = O(R(n-1,i-1)) + O(R(n-1,i-2)) + ...

This thing is recursive, recursive group is i = 0 or n = 0.

Therefore, the complexity is O (i ^ 2) a! The maximum size is 100 i (i is an upper limit m). . . This may sound a little bit reasonable complexity.

Then you write code.

code:

 

#include <bits/stdc++.h>
using namespace std;

Long  Long MOD = + 1E9 . 7 ;
 Long  Long B [ 105 ];
 Long  Long Power ( Long  Long NUM, Long  Long K) {
    num %= mod;
    long long ans = 1;
    while(k) {
        if(k & 1) ans = ans * num % mod;
        k >>= 1;
        num = num * num % mod;
    }
    return ans;
}
long long C(int x,int y) {
    //懒得写复杂度低的了,反正就100
    long long ans = 1;
    for(int i = 0;i < y;++i) {
        ans = ans * (x-i) % mod;
        ans = ans * power(i+1,mod-2) % mod;
    }
    return ans;
}
long long a;
long long R(long long n,long long k) {
    if(n == 0) {
        if(k == 0) return 1;
        return 0;
    }
    if(k == 0) {
        long long ans = (power(a,n+1)-a+mod)%mod;
        ans = ans * power(a-1,mod-2) % mod;
        return ans;
    }

    long long ans = (a - power(a,n+1)*power(n,k)%mod + mod ) % mod;
    for(int i = 0;i <= k-1;++i) {
        ans = (ans + a * C(k,k-i) % mod * R(n-1,i)) % mod;
    }
    ans = mod - ans;
    ans = ans * power(a-1,mod-2) % mod;
    return ans;
}

int main() {
    long long n,m;
    cin >> n >> m >> a;
    long long ans = 0;
    for(int i = 0;i <= m;++i) {
        scanf("%lld",&b[i]);
        ans += b[i] * R(n,i) % mod;
        ans %= mod;
    }
    cout << (ans+1)%mod << endl;
    return 0;
}

 对了下样例,反正样例都对了,假装自己已经ac

Guess you like

Origin www.cnblogs.com/obob/p/12400162.html