Cod sursa(job #2417099)

Utilizator Andrei-27Arhire Andrei Andrei-27 Data 28 aprilie 2019 21:11:13
Problema Numerele lui Stirling Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>
using namespace std ;
ifstream in ("stirling.in") ;
ofstream out ("stirling.out") ;
int s [ 205 ][ 205 ] , S [ 205 ][ 205 ] , q ;
int main() {
    int i , j , tip , x , y ;
    in >> q ;
    s [ 1 ][ 1 ] = 1 ;
    S [ 1 ][ 1 ] = 1 ;
    for ( i = 2 ; i <= 200 ; ++ i )
        for ( j = 1 ; j <= i ; ++ j ) {
            s [ i ][ j ] = s [ i - 1 ][ j - 1 ] - ( i - 1 ) * s [ i - 1 ][ j ] ;
            S [ i ][ j ] = S [ i - 1 ][ j - 1 ] + j * S [ i - 1 ][ j ] ;
        }
    while ( q -- )  {
        in >> tip >> x >> y ;
        if ( tip == 1 ) out << s [ x ][ y ] << '\n' ;
        else            out << S [ x ][ y ] << '\n' ;
    }
}