CHEFADD - EDITORIAL

XDDDDDDDDD

@aryanc403 - @taran_1407 knows everything about girls in his college, as evident from his statement :wink:

@vijjji123 - Sadly there, there is only disappointment from me in your fate. I wont be writing editorials for a long, long time XD.

@ everyone

I just hope next time you all will read my comment carefully. I explicitly mentioned “As far as I know” xD

All of these pairs are not valid.

For verification, write a brute program which iterates over all pairs of (i, c-i) and count the number pairs in which i have same bit count as a and (c-i) has the same bit count as B.

Glad you found it useful.

Add two numbers in binary form.

1010

0110

you’ll see, that sum is 10000. This happened due to carry forward at bit index 1, 2 and 3 (counting from least significant to most significant). Analyse this example and you’ll get it.

can you please give one more example explaining this x, cf and y.

Other examples would be similar. I recommend you read and Binary Arithmetic (specifically Binary addition), which you may find by googling.

Please dont make fun of me or taran!

I did not get what you want to say.

In your solution, if we add an extra condition in recursive function ans
a == 0&& b== 0 return 0 gives WA. Why ?
and why do we need to add condition bit==B ??

I couldn’t understand your code

Because cf may be balancing the remaining bits as required for c.

Like, suppose we have a==0 && b==0. we need the current bit to be 1, and cf is also 1. Hence, This bit we get from cf. Assuming all next bits are 0, we have one way which, due to that condition, will be missed.

1 Like

Almost similar problem A. XOR Equation.

@taran_1407 Thanks :slight_smile:

@taran_1407 can you please look into my code…why its giving wa for 2 test cases.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int v[32][32][32][2];
int count(int n)
{
int a=0;
while(n)
{
a++;
n=n&(n-1);
}
return a;
}
int call(int a,int b,int c,int d,int x)
{ int n=log2©;
if(a<0||b<0)return 0;
//cout<<a<<" “<<b<<” “<<x<<” “<<d<<”\n";
if(d==n+1) return (a==0&&b==0&&x==0);
if(v[a][b][d][x]!=-1)return v[a][b][d][x];

if(((c>>d)&1)==x)
{
    int p=call(a,b,c,d+1,0);
    int q=call(a-1,b-1,c,d+1,1);
    return v[a][b][d][x]=p+q;
}
else
{   if(x)
    {int p=call(a-1,b,c,d+1,1);
    int q=call(a,b-1,c,d+1,1);
        return v[a][b][d][x]=p+q;
    }
    else
    {int p=call(a-1,b,c,d+1,0);
    int q=call(a,b-1,c,d+1,0);
    return v[a][b][d][x]=p+q;}
}

}
signed main() {
int t;
cin>>t;
while(t–)
{
int a,b,c,i,j,k;
cin>>a>>b>>c;
a=count(a);
b=count(b);
for(i=0;i<10;i++)
for(j=0;j<10;j++)
for(k=0;k<10;k++)
{
v[i][j][k][0]=-1; v[i][j][k][1]=-1;
}
cout<<call(a,b,c,0,0)<<"\n";
}
return 0;
}