Site Message

Only Premium Users can view the Question

Site Message

Only Premium Users can view the Question

Site Message

Only Premium Users can view the Question

Site Message

Only Premium Users can view the Question

Question: Samsung R&D Recently asked Online Assessments Questions (BIT MESRA ; 6M + FTE) | String Amplifier | 20th September 2023
1
Entering edit mode

ADD COMMENTlink 2.5 years ago Delta 3.0k
0
Entering edit mode

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int factor(vector<vector<int>>&a,int n,int m)
{
    int count=0;
    for(int i=0;i<n;i++)
    {
        int flag=0;
        for(int j=0;j<m;j++)
        {
            if(a[i][j]==0)
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        count++;
    }
    return count;
}
int maxfactor(vector<vector<int>>&a,int n,int m,int k,int col)
{
    if(k==0)
    {
        return factor(a,n,m);
    }
    if(col>=m)
    return 0;
    int temp=maxfactor(a,n,m,k,col+1);
    for(int i=0;i<n;i++)
    {
        a[i][col]=!a[i][col];
    }
    int temp2=maxfactor(a,n,m,k-1,col);
    for(int i=0;i<n;i++)
    {
        a[i][col]=!a[i][col];
    }
    return max(temp,temp2);
}
int main()
{
    int n,m,k;
    cin>>n>>m;
    vector<vector<int>>a(n,vector<int>(m));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    
    cin>>k;
    cout<<maxfactor(a,n,m,k,0);
    return 0;
}
 

ADD COMMENTlink 2.5 years ago Dhruv Agarwal • 0
Entering edit mode
0

it is brute force ,will it pass all testcases ?

ADD REPLYlink 2.5 years ago
Dexter
• 0
Entering edit mode
0

I Think we can not use STL ..

ADD REPLYlink 2.5 years ago
TUSHAR KUMAR
• 0
0
Entering edit mode
ll dp[21][21] ;
ll cal(ll j , ll n ,ll m , vector<vll>&arr, ll mask )
{

    if(j==m)
    {
        ll ans =0 ; 
        fl(i ,0 ,n )
        {
            ll f= 0;
            fl(j , 0, m )
            {
               if(mask&(1<<j))
               {
                 if(arr[i][j]>0)
                 {
                    f=1 ;
                    break ;
                 }
               }
               else
               {
                     if(arr[i][j]<0)
                 {
                    f=1 ;
                    break ;
                 }
               }
            }
            if(!f)
            ans++ ;
        }
        return ans ;
    }

    if(dp[j][mask]!=-1)
    return dp[j][mask]; 


    ll t=0 ,nt =0 ; 
    t = cal(j+1, n ,m , arr , mask|(1<<(j))) ;
    nt= cal(j+1, n , m, arr ,mask ) ;
   return dp[j][mask] = max(t, nt ) ;
}



void solve()
{

ll n ,m , k ;cin >> n>> m>> k ; 
vector<vll>arr(n , vll(m)) ;
fl(i ,0 ,n )
{
    fl(j ,0 , m)
    cin >> arr[i][j] ;
}
memset(dp , -1 ,sizeof(dp)) ;
cout << cal(0 , n , m ,arr , 0 ) ;

 
}

 

ADD COMMENTlink 2.4 years ago Kshitiz Kumar • 0
0
Entering edit mode

I think the simple logical explanation will be

 

1.) find all the similar rows. why?? (beacause only similar rows after applying ant operation to column will reflect similar changes);

2,) print(count of max(similar rows) if num zeroes<=k)

ADD COMMENTlink 2.4 years ago Yololo • 20
Entering edit mode
0

Kindly do let me know if this approch is correct

ADD REPLYlink 2.4 years ago
Yololo
• 20
0
Entering edit mode

can u send all the questions

ADD COMMENTlink 2.4 years ago ADARSH RANJAN • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts