Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined), problem: (D) Felicity’s Big Secret Revealed Solution in C/C++

#include<stdio.h>
#define m 1000000007u
typedef unsigned u;
u D[76][1u<<20],S[1u<<20];
char C[76];
u V[76][76];
int main()
{
	u n,i,j,k,N=1u<<20,b,r=0;
	scanf("%u",&n);
	scanf("%s",C);
	for(i=-1;++i<n;)for(j=i-1,k=0;++j<n;)
	{
		k=k<<1|(C[j]=='1');
		V[i][j]=k;
	}
	for(i=-1;++i<=n;)D[i][0]=1;
	for(i=-1;++i<n;)
	{
		for(j=i-1;++j<n;)
		{
			if(!V[i][j])continue;
			if(V[i][j]>20)break;
			b=1u<<(V[i][j]-1);
			for(k=-1;++k<N;)
			if((D[j+1][k|b]+=D[i][k])>=m)D[j+1][k|b]-=m;
		}
	}
	for(i=-1;++i<=n;)
	{
		for(j=1;j<N;j=j<<1|1)
		if((r+=D[i][j])>=m)r-=m;
	}
	printf("%u\n",r);
	return 0;
}
#include<stdio.h>
#define m 1000000007u
typedef unsigned u;
u D[76][1u<<20],S[1u<<20];
char C[76];
u V[76][76];
int main()
{
	u n,i,j,k,N=1u<<20,b,r=0;
	scanf("%u",&n);
	scanf("%s",C);
	for(i=-1;++i<n;)for(j=i-1,k=0;++j<n;)
	{
		k=k<<1|(C[j]=='1');
		V[i][j]=k;
	}
	for(i=-1;++i<=n;)D[i][0]=1;
	for(i=-1;++i<n;)
	{
		for(j=i-1;++j<n;)
		{
			if(!V[i][j])continue;
			if(V[i][j]>20)break;
			b=1u<<(V[i][j]-1);
			for(k=-1;++k<N;)
			if((D[j+1][k|b]+=D[i][k])>=m)D[j+1][k|b]-=m;
		}
	}
	for(i=-1;++i<=n;)
	{
		for(j=1;j<N;j=j<<1|1)
		if((r+=D[i][j])>=m)r-=m;
	}
	printf("%u\n",r);
	return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

7 Reasons This Viral Kitchen Gadgets Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.Most products in this category disappoint within weeks. Cheap materials, vague instructions, and results that...

Trump lays out the pomp for Xi but says little about the significant tensions in US-China relations

A Grand Diplomatic Spectacle Amid Underlying Geopolitics In a high-profile diplomatic engagement that blended elaborate ceremonial fanfare with cautious statecraft, Donald Trump welcomed Chinese President...

Everything You Need to Know About Viral Kitchen Gadgets Right Now

There comes a point when you realise that tolerating a frustrating situation is costing you more than just fixing it properly. That was the...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!