求问为什么#8#10会wa
查看原帖
求问为什么#8#10会wa
218365
2B_dada楼主2021/10/30 19:37

使用了dp+树状数组,和答案就差了1就离谱。

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int n = 0, ans = 0;
int f[40050] = {0};

struct node
{
    int l, w;
} Node[40050];

bool cmp(node a, node b)
{	
	if(a.l != b.l) return a.l > b.l;
    else return a.w > b.w; 
}

int lowbit(int in)
{
    return in&(-in);
}

void add(int in, int pos)
{
    while(pos <= 40050)
    {
        f[pos] = max(in, f[pos]);
        pos += lowbit(pos);
    }
}

int getMax(int pos)
{
    int tmax = 0;
    while(pos > 0)
    {
        tmax = max(tmax, f[pos]);
        pos -= lowbit(pos);
    }
    return tmax;
}

int main()
{
    //freopen("P1233_8.in.txt","r",stdin);
    scanf("%d",&n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d %d",&Node[i].l,&Node[i].w);
	}
    sort(Node+1,Node+1+n,cmp);
    
    for (int i = 1; i <= n; i++)
    {
        printf("%d %d\n",Node[i].l,Node[i].w);
	}
	for (int i = 1; i <= n; i++)
    {
    	if(i == 1 || Node[i-1].w!=Node[i].w)
		{
    		add(getMax(Node[i].w)+1,Node[i].w);
		}
	}
	ans = getMax(40050);
    printf("%d",ans);
    
    return 0;
}
2021/10/30 19:37
加载中...