Advertisement
rotti321

Untitled

Mar 6th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. void citire(int a[100][100],int &n,int &m)
  5. {
  6.     ifstream f("flip.in");
  7.     f>>n>>m;
  8.     for(int i=1;i<=n;i++)
  9.         for(int j=1;j<=m;j++)
  10.             f>>a[i][j];
  11. }
  12. int rezolva(int a[100][100],int n,int m,int x)
  13. {
  14.     int s,rez=0;
  15.     for(int i=1;i<=n;i++)
  16.     {
  17.         s=0;
  18.         for(int j=1;j<=m;j++)
  19.         {
  20.             s+=(x & (1<<(j-1)))?a[i][j]:-a[i][j];
  21.        /**     if(x & (1<<(j-1)))
  22.                 cout<<"-";
  23.             else
  24.                 cout<<"+";  **/
  25.         }
  26.         rez+=abs(s);
  27. ///      cout<<endl;
  28.     }
  29.   ///  cout<<endl;
  30.     return rez;
  31. }
  32.  
  33. int main()
  34. {
  35.     int a[100][100],n,m,rez=0;
  36.     ofstream g("flip.out");
  37.     citire(a,n,m);
  38.     for(int ocupat=0;ocupat<(1<<m);ocupat++)
  39.         rez=max(rez,rezolva(a,n,m,ocupat));
  40.     g<<rez;
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement