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

uva的100题

Posted by failgod at 2007-04-20 13:29:45
这个题我用DP作的,第一次用DP(表鄙视我),前900的数,没问题,到900之后就有问题了,其中920--930之间结果是179,但在920--930之间的数单个测试最大是130。请各位帮忙看一下,问题在什么地方?
原题http://acm.uva.es/p/v1/100.html
代码:
   int a[20000];//最为过程表

void main()
{
	int j,temp,max=0,i=0,fn,sn;
	long int n,count,b[1000];//b[]数组作为栈来使用
	for(n=0;n<=999;n++)
	{b[n]=0;}  
         a[1]=1;
	printf("\ninput first int:");
	scanf("%d",&fn);
	printf("\ninput second int:");
	scanf("%d",&sn);
	for(;fn<=sn;fn++)
	{
	  i=1;
	  n=fn;
	  if(n<20000 && a[n]!=0) temp=a[n];
	  else
	  {
	    do
	    {
	      b[i-1]=n;
	      i++;
               /*  printf("  %d   ",n);   */
	      if((n%2)!=0) n=3*n+1;
               else n=n/2;
               if( n<20000 && a[n]!=0 && n!=1){ i=a[n]+i;break;}
               /*   	printf("  -=%d=-  ",i);  */
             }while(n!=1);
          temp=i;
          for(j=0;j<=i-1;j++)
          {
            count=b[j];
            i--;
            if(0==a[count]&&count<20000)a[count]=i;
            else continue;
          }
         }
         max= temp>max ? temp:max;
        }
       printf("\n max:%d",max);
}

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