• <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個1,j有6種情況。
            dp[i][0] = dp[i - 1][1] 表示偶數個1,且最后一個1在末尾。
            dp[i][1] = dp[i - 1][0] + dis 表示奇數個1,且最后一個1在末尾。
            dp[i][2] = f[i - 1][2] + f[i - 1][0] 表示偶數個1,且最后一個1不在末尾。
            dp[i][3] = f[i  - 1][3] + f[i - 1][1] 表示偶數個1,且最后一個1不在末尾。
            dp[i][4] = f[i - 1][4] + (dis - 1) * f[i - 1][0] 表示偶數個1,且最后一個是0不在末尾。
            dp[i][5] = f[i - 1][5] + (dis - 1) * f[i - 1][0] 表示偶數個1,且最后一個是0不在末尾。
            上面六個關系式列舉了所以情況,但是只用到了(dp[i][0], dp[i][1], dp[i][3], dp[i][5])四個式子。

            友情提示,ans是超過int的,用long long吧,我因為這個吃了三次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 閱讀(244) 評論(0)  編輯 收藏 引用 所屬分類: 動態規劃
            麻豆成人久久精品二区三区免费 | 久久99精品综合国产首页| 亚洲精品乱码久久久久久蜜桃不卡 | 亚洲午夜久久久久久久久久| 久久精品无码午夜福利理论片| 人人狠狠综合久久亚洲婷婷| 亚洲欧美成人久久综合中文网| 久久婷婷五月综合色奶水99啪| 亚洲国产二区三区久久| 久久成人国产精品免费软件| 色噜噜狠狠先锋影音久久| 一本一本久久aa综合精品| 国产高潮久久免费观看| 久久精品亚洲日本波多野结衣| 日本国产精品久久| 国产成人99久久亚洲综合精品 | 一本一本久久a久久精品综合麻豆| 久久久久亚洲AV片无码下载蜜桃 | 久久精品国产亚洲av麻豆小说| 久久亚洲精品无码播放| 亚洲国产精品久久66| 国产精品久久永久免费| 午夜天堂精品久久久久| 亚洲国产成人精品久久久国产成人一区二区三区综 | 中文字幕无码久久精品青草 | 日韩欧美亚洲综合久久影院Ds| 久久美女人爽女人爽| 久久精品蜜芽亚洲国产AV| 日韩久久久久久中文人妻| 99精品国产99久久久久久97 | 亚洲国产成人乱码精品女人久久久不卡| 99久久无码一区人妻a黑| 久久精品中文闷骚内射| 久久婷婷五月综合色奶水99啪| 久久久久人妻一区二区三区| 久久久久久国产精品无码下载| 国产亚洲美女精品久久久2020| 久久久无码精品亚洲日韩京东传媒 | 思思久久99热只有频精品66| 午夜精品久久久久| 亚洲精品无码专区久久久|