"Bitset" hdu4920 Matrix multiplication

Source: Internet
Author: User

The first two matrices are all mod3.

S[i][j][k] indicates that the nth bit of the row/column of the first I (0/1) matrix is J (1/2).

Then if a couple of moments on the corresponding bit is 1, 1, multiply is 1;

1, 2:2;

2, 1:2;

2, 2:1.

Then divide the bitset and up in these four cases, then count the number of counts () and calculate the contribution to the position of the answer matrix.

 #include <cstdio> #include <bitset>using namespace std; #define N 801int N,x;bitset<n>s[2][2][n];int Main () {while (scanf ("%d", &n)!=eof) {for (int i=1;i<=n;++i) {s[0][0    ][i].reset ();    S[0][1][i].reset ();    S[1][0][i].reset ();    S[1][1][i].reset ();        } for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {scanf ("%d", &x);        int op=x%3-1;      if (op!=-1) s[0][op][i][j]=1;        } for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {scanf ("%d", &x);        int op=x%3-1;      if (op!=-1) s[1][op][j][i]=1;        }for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {printf ("%d", ((S[0][0][i]&s[1][0][j]). COUNT () + ((S[0][0][i]&s[1][1][j]). Count () <<1) + ((S[0][1][i]&s[1][0][j]). Count () <<1) + (s[0][1][        I]&S[1][1][J]). Count ())%3); Putchar (j==n? ')      \ n ': '); }}return 0;} 

"Bitset" hdu4920 Matrix multiplication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.