Pagini recente » Cod sursa (job #2511953) | Cod sursa (job #1082466) | Cod sursa (job #2227402) | Cod sursa (job #2422005) | Cod sursa (job #2808618)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("cowfood.in");
ofstream fout ("cowfood.out");
int const mod = 3210121 , N = 2e4 + 7;
int k , s , n , fact [N] , val [21][31] , v [31];
void getfact (){
fact [0] = 1;
for(int i = 1 ; i < N ; ++ i)
fact [i] = 1LL * i * fact [i - 1] % mod;
}
int lgp (int a , int b){
int r (1) , c (a);
for(int j = 0 ; (1 << j) <= b ; ++ j){
if ((1 << j) & b)
r = 1LL * r * c % mod;
c = 1LL * c * c % mod;
}
return r;
}
int C (int n , int k){
return 1LL * fact [n] * lgp (fact [k] , mod - 2) * lgp (fact [n - k] , mod - 2) % mod;
}
int main()
{
fin >> k >> s >> n;
int total (0);
getfact ();
for(int i = k - 1 ; i < s ; ++ i){
total = total + C (i , k - 1);
if (total >= mod)
total -= mod;
}
for(int i = 0 ; i < n ; ++ i)
for(int j = 0 ; j < k ; ++ j)
fin >> val [i][j];
for(int i = 1 ; i < (1 << n) ; ++ i){
fill (v , v + k , 0);
int c (0);
for(int j = 0 ; (1 << j) <= i ; ++ j){
///iau experimentu j
if ((1 << j) & i){
++ c;
for(int y = 0 ; y < k ; ++ y)
v [y] = max (v [y] , val [j][y]);
}
}
int sum (0);
for(int y = 0 ; y < k ; ++ y)
sum += v [y];
if (sum > s)
continue;
int nr = (C (s - sum - 2 + k , k - 1) + 1) % mod;
if (c % 2)
total = total + mod - nr;
else
total = total + nr;
total %= mod;
}
fout << total << '\n';
return 0;
}