Cod sursa(job #1715431)

Utilizator Bodo171Bogdan Pop Bodo171 Data 10 iunie 2016 17:35:04
Problema Cowfood Scor 4
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <iostream>
#include<fstream>
using namespace std;
const long long mod=3210121;
long long a[25][35],s,p,tot,comp[35];
int i,j,fix,n,k,nr,x;
int main()
{
    ifstream f("cowfood.in");
    ofstream g("cowfood.out");
    f>>k>>s>>n;
    for(i=1;i<=n;i++)
        for(j=1;j<=k;j++)
         f>>a[i][j];
    fix=(1<<n)-1;
    for(i=1;i<=fix;i++)
    {
        for(j=1;j<=k;j++) comp[j]=0;
        nr=0;p=1;
        for(j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                for(x=1;x<=k;x++)
                    comp[x]=max(comp[x],a[j+1][x]);
                nr++;
            }
        }
        for(x=1;x<=k;x++)
         p=p*(s-comp[x]+1)%mod;
        if(nr%2==1) {tot+=p;if(tot>=mod)tot-=mod;}
        else {tot-=p;if(tot<0) tot+=mod;}

    }
    p=1;
    for(i=1;i<=k;i++) p=(p*s)%mod;
    tot=p-tot;
    if(tot<0) tot+=mod;
    g<<tot;
    return 0;
}