POJ1609 Tiling Up Blocks

无情的一题!!!

读了半小时题,才把题目看懂,发现是LIS后写了二分的那种方法,node[i]向ans[i]赋值的时候len++了两次,样例跑不出来,从机房走出去看见一只小猫,回来就发现了bug

=。=

结果一提交,RE,检查发现n最大10000我开的22222,没开小,百度里面看到有人也用这个方法提交后也是RE。。。自己出了几组数据后发现貌似不能用二分写呢(至少我还没想到该怎么改,看到后知道怎么改的筒子请私信=。=)

下面是RE二分代码

#include <iostream>
#include<stdio.h>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 10010
using namespace std;

struct Node
{
    int x,y;
}node[N];
struct Ans
{
    int x,y;
}ans[N];

int len;
int binary_search(int i)
{
    int le,ri,mid;
    le=1;ri=len;
    while(le<=ri)
    {
        mid=(ri+le)/2;
        if(node[i].x<=ans[mid].x&&node[i].y<=ans[mid].y)
               ri=mid;
               else
               le=mid+1;
    }
    return le;
}

int cmp(Node a,Node b)
{
    if(a.x==b.x)
    return a.y<=b.y;
    else
    return a.x<b.x;
}
int main()
{
    int n;
    while(scanf("%d",&n)&&n)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d %d",&node[i].x,&node[i].y);
        }
            sort(node+1,node+1+n,cmp);
            ans[1].x=node[1].x; ans[1].y=node[1].y;
            len=1;
         for(int i=2;i<=n;i++)
         {
             if(node[i].x>=ans[len].x&&node[i].y>=ans[len].y)
             {
                 len++;
                 ans[len].x=node[i].x; ans[len].y=node[i].y;
             }
             else
             {
                 int pos=binary_search(i);
                 ans[pos].x=node[i].x;
                 ans[pos].y=node[i].y;
             }
         }
         cout<<"-----------"<<endl;
         for(int i=1;i<=n;i++)
        {
            printf("%d %d\n",node[i].x,node[i].y);
        }
           cout<<"------------"<<endl;
        for(int i=1;i<=len;i++)
        cout<<ans[i].x<<" "<<ans[i].y<<endl;
         //printf("%d\n",len);
    }
        printf("*\n");
    return 0;
}
/*
5
1 1
2 6
3 3
4 2
5 5
5
1 1
2 6
4 4
3 8
5 3
*/

其实l和m给的范围蛮小的,只有100,换方法喽
<pre name="code" class="cpp">#include<stdio.h>
#include<string>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 22222
using namespace std;
int dp[110][110];
struct Node
{
    int x,y;
}node[N];

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n==0)break;
        memset(dp,0,sizeof dp);

        for(int i=1;i<=n;i++)
        {
            scanf("%d %d",&node[i].x,&node[i].y);
             dp[node[i].x][node[i].y]++;
        }

        for(int i=1;i<=100;i++)
        for(int j=1;j<=100;j++)
        {
            dp[i][j]+=max(dp[i][j-1],dp[i-1][j]);
        }
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            if(dp[node[i].x][node[i].y]>ans)
            ans=dp[node[i].x][node[i].y];
        }
        printf("%d\n",ans);
    }
    printf("*\n");
    return 0;
}

POJ1609 Tiling Up Blocks

时间: 2024-10-29 23:28:15

POJ1609 Tiling Up Blocks的相关文章

POJ1609:Tiling Up Blocks(DP)

Description Michael The Kid receives an interesting game set from his grandparent as his birthday gift. Inside the game set box, there are n tiling blocks and each block has a form as follows: Each tiling block is associated with two parameters (l,m)

[2016-03-11][POJ][1609][Tiling Up Blocks]

[2016-03-11][POJ][1609][Tiling Up Blocks] Tiling Up Blocks Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u Submit Status Description Michael The Kid receives an interesting game set from his grandparent as his birthday gift. I

POJ 1609 Tiling Up Blocks.

~~~~ 二维的最长上升子序列.n^2算法居然可以水过.. 就不多说了,排个序,然后DP. 题目链接:http://poj.org/problem?id=1609 ~~~~ #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #define N 11111 using namespace std; struct node { int l,m; }b[N]; boo

poj 1609 Tiling Up Blocks dp入门之记忆化搜索

题意: 给n个二元组(a,b),要在其中找最长的序列,使得对序列中的任意i<j,有ai<=aj且bi<=bj. 分析: 设dp[a][b]代表以(a,b)结尾的最长序列长度,记忆化搜索即可. 代码: //poj 1609 //sep9 #include <iostream> using namespace std; const int max_p=128; int n; int num[max_p][max_p]; int dp[max_p][max_p]; int sear

POJ 1609 二维递推

Tiling Up Blocks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5176   Accepted: 2028 Description Michael The Kid receives an interesting game set from his grandparent as his birthday gift. Inside the game set box, there are n tiling bl

DP题目列表/弟屁专题

声明: 1.这份列表不是我原创的,放到这里便于自己浏览和查找题目. ※最近更新:Poj斜率优化题目 1180,2018,3709 列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 195

[转] POJ DP问题

列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029, 2039, 2063, 20

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************

【Code::Blocks】windows 环境下编译 Code::Blocks(已修正)

Code::Blocks 在2012-11-25发布了最新的12.11版本,相比上一个版本(10.05),Code::Blocks 进行了许多改进和更新(Change log). 引用 Wikipedia:Code::Blocks: Code::Blocks是一个免费.开源.跨平台的IDE,使用C++开发,并且使用wxWidgets做为GUI函式库.Code::Blocks使用了插件架构,其功能可以使用插件自由地扩充.目前, Code::Blocks主要针对开发C/C++程式而设计. Code: