Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:wa的不行了....达人指点一下...那里错了

Posted by s_1 at 2005-09-01 17:29:17 on Problem 2597
In Reply To:wa的不行了....达人指点一下...那里错了 Posted by:wavemoon at 2005-08-28 19:33:53
无聊啊,竟然把S和E还要颠倒地给出.无聊
竟然要在这个地方卡人~~~~~
> #include<iostream.h>
> #include<stdlib.h>
> typedef struct lll
>   {
>   long long x,y;
>   }Line;
> Line a[1000];
> long long n;
> long long map[1000][1000];
> int cmp(const void*a,const void*b)
> {
>   Line aa,bb;
>   aa=*(Line*)a;
>   bb=*(Line*)b;
>   if(aa.y!=bb.y) {
>         if(aa.y>bb.y) return 1;
>         else return -1;
>          }    
>   else {
>       if(aa.x>bb.x) return 1;
>       else if(aa.x==bb.x) return 0;
>       else return -1;
>       }      
> }
> 
> long long dfs(long long ii,long long now)//从下标ii->n中去now个不相交的线段方案数
> {
>    long long tp,i,j;   
>    if(now==1) return n-ii; 
>    if(map[ii][now]!=-1l)
>       return map[ii][now];
>    tp=0;
>    for(i=ii;i<n-now;i++)
>       {
>         for(j=i+1;j<n-now+1;j++)
>            if(a[j].x>=a[i].y) 
>               break;
>         if(j<n)
>              tp+=dfs(j,now-1);
>       }
>   map[ii][now]=tp;     
>   return tp;
> }                       
>  
> 
> main()
> {
>   long long i,j,edg,k;
>   while(cin>>n)
>   {
>     for(i=0;i<n;i++)
>       { 
>         cin>>a[i].x>>a[i].y;
>         if(a[i].x>a[i].y)//x存首端点..y存尾端点..
>         {
>            k=a[i].x;
>            a[i].x=a[i].y;
>            a[i].y=k;
>         }
>       }                   
>     for(i=0;i<=n;i++)
>         for(j=0;j<=n;j++)
>             map[i][j]=-1l;
>     qsort(a,n,sizeof(a[0]),cmp);  //按y排序
>     edg=a[0].y;  //贪心求最大可剩余的线段数
>     k=1; 
>     for(i=1;i<n;i++)
>       if(a[i].x>=edg)
>         {
>          k++;
>          edg=a[i].y;
>         }  
>     j=dfs(0,k);  //选取不相交的k个线段方案数..对应擦除n-k条直线方案数
>     cout<<n-k<<" "<<j<<endl;
>    }
> }    
>   

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator