• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 7,comments - 3,trackbacks - 0

            Max Xor Sub-sequence II 
            Time Limit:1000MS  Memory Limit:32768K

            Description:

            Give you a sequence of integer numbers which are 1 or 0. You are to find the number of consecutive sub-sequence, which the xor value between all these numbers has the maximum value. The first number of the sequence is 1 and the last is 1. There are (n+1) 1’s in the sequence. N numbers will be given. The i-th number is the index of (i+1)-th 1 minus the index of i-th 1. For example: if the sequence is 1010100010001, 4 2 2 4 4 will be given.

             

            Input:

            There are multiple cases. For each case: Line 1: A single integer N (1<=N<=20000). Followed N integers ranging from 1 to 20000.

            Output:

            For each case output the result in a single line.

            Sample Input:

            4
            2 2 4 4
            5
            3 1 2 4 5
            

            Sample Output:

            49
            70
            

            Hint:

            1.1 ^ 1 = 0, 1 ^ 0 = 1, 0 ^ 1 = 1, 0 ^ 0 = 0. 2.In the example, sub-sequence 10 has the maximum value ‘cause 1 xor 0 = 1;the same as 10101, 1010100010001, and so on.

            算不上DP的DP......就是處理01串的奇偶性.....
            DP[i][j]表示第i個(gè)1,j有6種情況。
            dp[i][0] = dp[i - 1][1] 表示偶數(shù)個(gè)1,且最后一個(gè)1在末尾。
            dp[i][1] = dp[i - 1][0] + dis 表示奇數(shù)個(gè)1,且最后一個(gè)1在末尾。
            dp[i][2] = f[i - 1][2] + f[i - 1][0] 表示偶數(shù)個(gè)1,且最后一個(gè)1不在末尾。
            dp[i][3] = f[i  - 1][3] + f[i - 1][1] 表示偶數(shù)個(gè)1,且最后一個(gè)1不在末尾。
            dp[i][4] = f[i - 1][4] + (dis - 1) * f[i - 1][0] 表示偶數(shù)個(gè)1,且最后一個(gè)是0不在末尾。
            dp[i][5] = f[i - 1][5] + (dis - 1) * f[i - 1][0] 表示偶數(shù)個(gè)1,且最后一個(gè)是0不在末尾。
            上面六個(gè)關(guān)系式列舉了所以情況,但是只用到了(dp[i][0], dp[i][1], dp[i][3], dp[i][5])四個(gè)式子。

            友情提示,ans是超過int的,用long long吧,我因?yàn)檫@個(gè)吃了三次WA.....

            代碼:

            #include <cstdio>
            #include <cstring>
            #include <iostream>
            using namespace std;

            int main()
            {
                long long dp[20010][7];
                long long n;
                long long dis;
                while (cin >> n)
                {
                    memset(dp, 0, sizeof(dp));
                    dp[1][0] = 0;
                    dp[1][1] = 1;
                    for (long long i = 2; i <= n + 1; ++i)
                    {
                        cin >> dis;
                        dp[i][0] = dp[i - 1][1];
                        dp[i][1] = dp[i - 1][0] + dis;
                        dp[i][3] = dp[i - 1][3] + dp[i - 1][1];
                        dp[i][5] = dp[i - 1][5] + (dis - 1) * dp[i - 1][1];
                    }
                    cout << dp[n + 1][1] + dp[n + 1][3] + dp[n + 1][5] << endl;
                }
                return 0;
            }

            posted on 2011-10-15 22:15 LLawliet 閱讀(238) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 動(dòng)態(tài)規(guī)劃
            中文字幕无码久久精品青草| 国内精品久久久久久久久电影网| 精品久久久无码21p发布| 国产精品99久久久精品无码 | 久久精品人人槡人妻人人玩AV| 亚洲精品无码久久千人斩| 99久久精品国产高清一区二区 | 色婷婷综合久久久久中文字幕| 久久久黄色大片| 国产成人久久精品区一区二区| 久久久久亚洲精品无码网址 | 久久精品中文字幕有码| 无码超乳爆乳中文字幕久久| 久久国产精品免费一区| 亚洲精品无码久久千人斩| 久久久久亚洲AV无码专区桃色| 久久精品aⅴ无码中文字字幕不卡| 久久久久国产视频电影| 99久久精品国产免看国产一区| 影音先锋女人AV鲁色资源网久久| 伊人久久免费视频| 久久福利青草精品资源站免费| 精品多毛少妇人妻AV免费久久| 国产精品狼人久久久久影院| 97精品伊人久久大香线蕉app| 久久强奷乱码老熟女网站| 久久国产精品二国产精品| 国产∨亚洲V天堂无码久久久| 亚洲精品无码久久久影院相关影片| 久久综合一区二区无码| 国产高清国内精品福利99久久| 九九久久99综合一区二区| 人妻无码久久一区二区三区免费 | a高清免费毛片久久| 一本色道久久99一综合| 色天使久久综合网天天| 久久精品中文无码资源站| 亚洲国产精品无码久久一区二区| 亚洲精品综合久久| 久久人人爽人人爽人人片AV东京热 | 久久人人爽人人爽AV片|