Matrix Multiplication

problem Link

Solutions

#include<stdio.h>>

using namespace std;
#define ll long long
#define fr(i,a,n) for(i=a;i<n;i++)
int a[550][550],b[550][550],c[550][550],d[550][550];
int main()
{
int j,i,n,k,co=0;
scanf(“%d”,&n);
{
for(i=0;i<n;i++) for(j=0;j<n;j++) scanf(“%d”,&a[i][j]);
for(i=0;i<n;i++) for(j=0;j<n;j++) scanf(“%d”,&b[i][j]);
for(i=0;i<n;i++) for(j=0;j<n;j++) scanf(“%d”,&c[i][j]);
fr(i,0,n)
{
fr(j,0,n)
{
if(a[i][j])
fr(k,0,n)
{
d[i][k]+=a[i][j]*b[j][k];

}

}
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(c[i][j]!=d[i][j])
{
co=1;
break;
}
if(co==1)
break;
}

if(co)
puts(“NO”);
else
puts(“YES”);
}
return 0;
}

Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in pku, Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s