现在的位置: 首页 > 综合 > 正文

HDOJ 4472 Count(递推)

2019年02月12日 ⁄ 综合 ⁄ 共 693字 ⁄ 字号 评论关闭

给你n个点,问能建出多少种完全对称的树【自己左右对称,左子树左右对称,右子树左右对称,左子树的左右子树也左右对称。。。直到只剩一个点】。

把子树看成一点,就可以直接加上前面已经算出来的值了。

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

const int maxn = 1e5 + 10;
struct Pad
{
        int w, s, sum;
        bool operator <(const Pad &argu) const
        {
                return sum > argu.sum;
        }
}pp[maxn];

int main()
{
        #ifdef BellWind
        freopen("I.in", "r", stdin);
        #endif // BellWind
        int n;
        while(~scanf("%d", &n))
        {
                __int64 wsum = 0;
                for(int i = 0; i < n; i++)
                {
                        scanf("%d%d", &pp[i].w, &pp[i].s);
                        pp[i].sum = pp[i].s + pp[i].w;
                        wsum += pp[i].w;
                }
                sort(pp, pp + n);
                __int64 ans = 0, tmp;
                for(int i = 0; i < n; i++)
                {
                        wsum -= pp[i].w;
                        tmp = wsum - pp[i].s;
                        if(tmp > 0)
                                ans = max(ans, tmp);
                }
                printf("%I64d\n", ans);
        }
        return 0;
}

抱歉!评论已关闭.