51Nod 1714 1位数SG异或打表

SG[i]表示一个数二进制下有i个1的SG值

SG[0]=0

打表:

#include<bits/stdc++.h>
using namespace std;
int sg[100];
int vis[30000000];
int maxnnow = 0, x;
int main() {
        sg[0] = 0;
        for (int i = 1; i <= 64; i++) {
                for (int j = 0; j <= maxnnow; j++) {
                        vis[j] = 0;
                }
                maxnnow = 0;
                for (int j1 = 0; j1 < i; j1++)
                        for (int j2 = j1; j2 < i; j2++)
                                for (int j3 = j2; j3 < i; j3++)
                                        for (int j4 = j3; j4 < i; j4++)
                                                for (int j5 = j4; j5 < i; j5++)
                                                        for (int j6 = j5; j6 < i; j6++)
                                                                for (int j7 = j6; j7 < i; j7++) {
                                                                        x = sg[j1] ^ sg[j2] ^ sg[j3] ^ sg[j4] ^ sg[j5] ^ sg[j6] ^ sg[j7];
                                                                        maxnnow = max(maxnnow, x);
                                                                        vis[x] = 1;
                                                                }
                for (int j = 0; j <= maxnnow + 1; j++) {
                        if (vis[j] == 0) {
                                sg[i] = j;
                                break;
                        }
                }
        }
        for(int i=1;i<=64;i++)
        cout<<sg[i]<<endl;
}

表打出来后面就很简单了

posted @ 2019-04-02 09:48  Aragaki  阅读(183)  评论(0编辑  收藏  举报