Cod sursa(job #955716)

Utilizator crisbodnarCristian Bodnar crisbodnar Data 1 iunie 2013 13:13:52
Problema Elimin Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream fin("elimin.in");
ofstream fout("elimin.out");

int n, m, r, c, a[200][200], x[200], maxim;
vector <int> sol;
bool car[200];

void Calculare()
{
    int sum = 0;
    for(int j=1; j<=m; j++)
    {
        int s = 0;
        for(int i=1; i<=n; i++)
        if(!car[i]) s += a[i][j];

        sol.push_back(s);
        sum += s;
    }

    partial_sort(sol.begin(), sol.begin()+c, sol.end());
    for(int i=0; i<c; i++)
    sum -= sol[i];
    sol.clear();

    if(maxim < sum) maxim = sum;

}

void Back(int k)
{
    if(k == r+1) Calculare();
    else
        for(int j=1; j<=n; j++)
        {
            x[k] = j;
            car[x[k]] = 1;
            Back(k+1);
            car[x[k]] = 0;
        }
}

int main()
{
    fin>>n>>m>>r>>c;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            fin>>a[i][j];

    Back(1);

    fout<<maxim;

    return 0;
}