Editorial for Tổng siêu hạng


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

uses math;
const base=1000000007;
var s:string;
    n,k,i:longint;
    x,y,z:int64;

function calc(y:int64;yy:longint):int64;
var r:int64;
begin
     if yy=1 then exit(y);
     r:=sqr(calc(y,yy shr 1)) mod base;
     if odd(yy) then exit(r*y mod base)
     else exit(r);
end;

begin
     while true do
     begin
          readln(s);
          if s='[END]' then break;
          if s='[CASE]' then
          begin
               readln(k,n);
               n:=n+k;
               inc(k);
               x:=1; y:=1;
               for i:=1 to k do
               begin
                    x:=x*(n-i+1) mod base;
                    y:=y*i mod base;
               end;
               z:=calc(y,base-2);
               writeln(x*z mod base);
          end;
     end;
end.

Code mẫu của happyboy99x

/*SRM 467, Div 1 - Level 2*/
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define sz(a) int((a).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(), _e = (c).end(); i != _e; ++i)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i,n) for(int i = 0, _n = (n); i < _n; ++i)
#define repd(i,n) for(int i = (n)-1; i >= 0; --i )
#define fo(i,a,b) for(int i = (a), _b = (b); i <= _b; ++i)
#define fod(i,a,b) for(int i = (a), _b = (b); i >= _b; --i)

#define INF 1000000000
#define N
#define MOD 1000000007

class SuperSum {
    private:
        long long sqr( long long x ) {
            return x * x;
        }

        long long pow_mod( int a, int n ) {
            if( n == 0 ) return 1;
            long long res = sqr(pow_mod(a, n/2)) % MOD;
            return n%2 ? (res * a) % MOD : res;
        }

        long long choose( int n, int k ) {
            long long res = 1;
            rep(i,k) {
                res = (res * (n-i)) % MOD;
                res = (res * pow_mod(i+1, MOD-2)) % MOD;
            }
            return res;
        }

    public:
        int calculate( int k, int n ) {
            return (int) choose(n+k, k+1);
        }
};

char s[50];

int main() {
    int n, k;
    while(scanf("%s",s) == 1 && strcmp(s, "[END]")) {
        scanf("%d%d",&k,&n);
        printf("%d\n", SuperSum().calculate(k,n));
    }
    return 0;
}

Code mẫu của ladpro98

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, a, b) for(int i = (a); i <=(b); i++)
#define FORD(i, a, b) for(int i = (a); i > (b); i--)
#define REPD(i, a, b) for(int i = (a); i >=(b); i--)
#define SZ(a) (int((a).size()))
#define ALL(a) (a).begin(), a.end()
#define PB push_back
#define MP make_pair
#define LL long long
#define LD long double
#define II pair<int, int>
#define III pair<int, II>
#define X first
#define Y second
#define VI vector<int>
const int MOD = 1000000007;
using namespace std;

III Euclid(int a, int b) {
    if (a == 0) return MP(b, MP(0, 1));
    III p = Euclid(b % a, a);
    return MP(p.X, MP(p.Y.Y - p.Y.X * (b / a), p.Y.X));
}

int inverse(int a, int n) {
    return (Euclid(a, n).Y.X + n) % n;
}

int C(int k, int n) {
    LL ans = 1;
    REP(i, n - k + 1, n)
        ans = ans * i % MOD;
    LL denom = 1;
    REP(i, 1, k) denom = denom * i % MOD;
    return ans * inverse(denom, MOD) % MOD;
}

int main() {
    ios :: sync_with_stdio(0);
    string str;
    int k, n;
    while (1) {
        cin >> str;
        if (str[1] == 'E') break;
        cin >> k >> n;
        n += k; k++;
        cout << C(k, n) << '\n';
    }
    return 0;
}

Code mẫu của RR

#include <iostream>
#include <cstdio>
#include <algorithm>
#define BASE 1000000007
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define ll long long
using namespace std;

char s[100];
int n,k;

int lt(int p,int k) {
    if (!k) return 1;
    if (k==1) return p;
    ll mid=lt(p,k>>1);
    mid=(mid*mid)%BASE;
    if (k&1) return (mid*p)%BASE;
    else return mid;
}

ll c(int n,int k) {
    ll res=1LL;
    FOR(i,n-k+1,n)
        res=(res*i)%BASE;
    FOR(i,1,k)
        res=(res*lt(i,BASE-2))%BASE;
    return res;
}

int main() {
    while (true) {
        gets(s);
        if (s[1]=='E') break;
        scanf("%d\n",&k);
        scanf("%d\n",&n);
        printf("%d\n",c(n+k,k+1));
    }
    return 0;
}

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>

long long UCLN(long long a,long long b)
{
     long long r;
     while(b!=0)
     {
         r=a%b;
         a=b;
         b=r;
     }
     return a;
}

int main()
{
  //  freopen("SUPERSUM.inp","r",stdin);
    char s[10];
    long long a[53],k,n;
    while(gets(s)>0)
    {
        if(s[0]!='[')
            continue;
        else if(s[1]=='E')
            break;
        else
        {
            scanf("%lld %lld",&k,&n);
            k=k+1;
          //  printf("\n %lld %lld\n",k,n);
            long long KQ=1;
            for(int i=0;i<k;i++)
                a[i] = n+i;
          //  printf("**** %lld  ***\n\n",a[k-1]);
           //  printf("\n %lld %lld\n",a[0],a[k-1]);
            for(int i=2;i<=k;i++)
            {
                int u=i;
                for(int j=0;j<k;j++)
                {
                     long long d=UCLN(a[j],u);
                     a[j]=a[j]/d;
                     u=u/d;
                }
            }
          //  printf("\n %lld %lld\n",a[0],a[k-1]);
            for(int i=0;i<k;i++)
            KQ = KQ*a[i]%1000000007;
            printf("%lld\n",KQ);
        }
    }
  //  getch();
}

Code mẫu của ll931110

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define BASE 1000000007
typedef long long ll;
using namespace std;

ll pw(int x,int p)
{
   if (!p) return 1;
   ll q = pw(x,p/2);
   q = (q * q) % BASE;
   if (p & 1) q = (q * x) % BASE;
   return q;
};

ll inv(int x)
{
   return pw(x,BASE - 2);
};

ll SS(int k,int n)
{
//   cout << k << ' ' << n << endl;
   ll ret = 1;
   for (int i = 0; i <= k; i++) ret = (ret * (n + i)) % BASE;
//   cout << "1st shot" << endl;
   for (int i = 1; i <= k + 1; i++) ret = (ret * inv(i)) % BASE;
   return ret;
};

int main()
{
//    freopen("ss.in","r",stdin);
//    freopen("ss.ou","w",stdout);
    string singal;
    while (1)
    {
          cin >> singal; // cout << singal << endl;
          if (singal == "[END]") break;
          int k,n;
          cin >> k >> n;
          cout << SS(k,n) << endl;
    };
};

Comments

Please read the guidelines before commenting.


There are no comments at the moment.