The romantic hero

Source: Internet
Author: User

Question Link

  • Question:
    N number. Find two subscripts I and j (I <j). In 1-I, select the bitwise AND value of several numbers equal to or equal to J-n, the two sets are not empty. Evaluate the number of sets that meet the condition.
  • Analysis:
    For an I instance, if you know all the values on the left and all the values on the right, the flight is part of the answer, and the DP is used to pre-process the values on one side.
    Focus on the DP status representation: DP [I] [J] indicates the number of cases where the number ends with an I-position number and the operation value is J, here, it indicates the sum of any number that can be combined and J. If it does not indicate that it ends with I, it will be repeated.
    In this case, why does Dp not repeat? For DP [x] [] and DP [y] [], because the maximum values of the two States are different, so the number of columns will not be the same, that is to say, the States represented by DP do not overlap. For a sequence, there is only one computing result, so it only belongs to a certain state of DP [x, it does not repeat (if a sequence can obtain multiple computing results, then DP cannot be like this, because a definite sequence can belong to multiple States ).

const int MAXN = 1024;int ipt[MAXN];LL dp1[MAXN][MAXN], dp2[MAXN][MAXN], sum1[MAXN][MAXN], sum2[MAXN][MAXN];int main(){    int T, n;    RI(T);    FE(kase, 1, T)    {        CLR(dp1, 0); CLR(sum1, 0);        CLR(dp2, 0); CLR(sum2, 0);        RI(n);        REP(i, n)            RI(ipt[i]);        dp1[0][ipt[0]] = sum1[0][ipt[0]] = 1;        FF(i, 1, n)        {            REP(j, MAXN)                dp1[i][j ^ ipt[i]] = (sum1[i - 1][j] + dp1[i][j ^ ipt[i]]) % MOD;            dp1[i][ipt[i]]++;            REP(j, MAXN)                sum1[i][j] = (sum1[i - 1][j] + dp1[i][j]) % MOD;        }        dp2[n - 1][ipt[n - 1]] = sum2[n - 1][ipt[n - 1]] = 1;        FED(i, n - 2, 0)        {            REP(j, MAXN)                dp2[i][j & ipt[i]] = (sum2[i + 1][j] + dp2[i][j & ipt[i]]) % MOD;            dp2[i][ipt[i]]++;            REP(j, MAXN)                sum2[i][j] = (sum2[i + 1][j] + dp2[i][j]) % MOD;        }        LL ans = 0;        REP(i, n - 1)            REP(j, MAXN)                ans = (ans + dp1[i][j] * sum2[i + 1][j]) % MOD;        cout << ans << endl;    }    return 0;}


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.