Editorial for Quan hệ


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

const fi='';
      fo='';
var p:array[0..10] of int64;
    a:array[2..10] of int64;
    b:array[1..10] of int64;
    t:longint;

function sum(i:longint):int64;
var j:longint; re:int64;
begin
     re:=0;
     for j:=1 to i do re:=re+b[j];
     sum:=re;
end;

function mul(i:longint):int64;
var j:longint; re:int64;
begin
     re:=1;
     for j:=1 to i do re:=re*p[b[j]];
     mul:=re;
end;


procedure find(pos,num:longint);
var i:int64;
begin
     i:=0;
     while i<num do
     begin
          inc(i);
          b[pos]:=i;
          if sum(pos)=num then a[num]:=a[num]+p[num] div mul(pos)
          else
          begin
               if sum(pos)<num then find(pos+1,num)
               else
               begin
                    b[pos]:=0;
                    break;
               end;
          end;
          b[pos]:=0;
     end;
end;

procedure init;
var i,j:longint; t:int64;
begin
     p[0]:=1; p[1]:=1;
     t:=1; j:=1;
     while t<10 do
     begin
          inc(t);
          inc(j);
          p[t]:=p[t-1]*t;
     end;
     fillchar(a,sizeof(a),0);
     for i:=2 to 10 do
         find(1,i);
end;

begin
     init;
     assign(input,fi);
     reset(input);
     assign(output,fo);
     rewrite(output);
     readln(t);
     while t<>-1 do
     begin
          writeln(a[t]);
          readln(t);
     end;
     close(input);
     close(output);
end.

Code mẫu của happyboy99x

#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;
typedef unsigned long long LL;

#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 11

LL f[N]; int n;

int main() {
    f[0] = f[1] = 1;
    fo(i,2,10) {
        LL c = 1;
        fo(j,1,i) {
            c = c * (i-j+1) / j;
            f[i] += c * f[i-j];
        }
    }
    while(scanf("%d",&n) && n != -1) printf("%llu\n", f[n]);
    return 0;
}

Code mẫu của RR

var
  f:array[1..11,0..11] of longint;
  sum:array[1..10] of longint;
  i,j,n:longint;
begin
  f[1,1]:=1;
  for i:=2 to 10 do
    for j:=1 to i do
      f[i,j]:=j*(f[i-1,j]+f[i-1,j-1]);

  for i:=1 to 10 do
    for j:=1 to i do inc(sum[i],f[i,j]);

  read(n);
  while (n>=0) do
    begin
      writeln(sum[n]);
      read(n);
    end;
end.

Code mẫu của hieult

#include <stdio.h>
main()
{
long a[10][10],b[10];
int n[10000],max;
for(int i=0;i<10;i++)
  a[i][0]=1;
for(int i=1;i<10;i++)
  for(int j=1;j<=i;j++)
    {
    if(j!=i)
     a[i][j]=(a[i-1][j]+a[i-1][j-1])*(j+1);
    else a[i][j]=a[i-1][j-1]*(j+1);
    }
for(int i=0;i<10;i++)
  {
  b[i]=0;
  for(int j=0;j<=i;j++)
    b[i]+=a[i][j];
  }
for(int i=1;;i++)
  {
  scanf("%d",&n[i]);
  if(n[i]==-1)
    {
    max=i;
    break;
    }
  }
for(int j=1;j<max;j++)
  printf("%ld\n",b[n[j]-1]);
}

Code mẫu của ll931110

{$MODE DELPHI}
program COND;
const
  maxn = 10;
var
  list,a: array[1..maxn] of integer;
  p,res: integer;

function calc(n,k: integer): integer;
var
  t,i: integer;
begin
  t := 1;
  for i := 1 to k do
    t :=  t * (n - i + 1) div i;
  calc := t;
end;

procedure addres;
var
  s,i,t: integer;
begin
  t := 1;
  s := 0;
  i := 1;

  while s < p do
    begin
      s := s + a[i];
      t := t * calc(s,a[i]);
      inc(i);
    end;

  res := res + t;
end;

procedure attempt(i,j: integer);
var
  k: integer;
begin
  for k := 1 to j do
    begin
      a[i] := k;
      if j = k then addres else attempt(i + 1,j - k);
    end;
end;

begin
  for p := 2 to 10 do
    begin
      res := 0;
      attempt(1,p);
      list[p] := res;
    end;

  repeat
    readln(p);
    if p <> -1 then writeln(list[p]);
  until p = -1;
end.

Code mẫu của khuc_tuan

import java.io.*;

public class Main {
    long[][] f, c;
    void init(){
        int i,j,l;
        f = new long[20][20];
        c = new long[20][20];
        for(i=1;i<=10;++i)
            for(j=1;j<=10;++j) c[i][j]=0;
        c[1][1] = 1;
        for(i=1;i<=10;++i) c[0][i] = 1;
        for(i=2;i<=10;++i)
            for(j=1;j<=i;++j) c[j][i] = c[j-1][i-1]+c[j][i-1];
        for(i=1;i<=10;++i)
            for(j=1;j<=i;++j) f[i][j]=0;
        f[1][1] = 1;
        for(i=2;i<=10;++i){
            f[i][1] = 1;
            for(j=2;j<=i;++j)
                for(l=1;l<=i-j+1;++l)
                    f[i][j] += f[i-l][j-1]*c[l][i];
        }
    }
    long cal(int n){
        long r=0;
        for(int j=1;j<=n;++j) r+= f[n][j];
        return r;
    }
    void run() throws Exception{
        BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
        init();
        while(true){
            int n = Integer.parseInt(kb.readLine());
            if(n==-1) break;
            System.out.println(cal(n));                     
        }
    }
    public static void main(String[] Args) throws Exception{
        new Main().run();
    }

}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.