1 条题解

  • 0
    @ 2021-6-15 1:39:12

    C :

    #include <stdio.h>
    
    int   ans[81]={0};
    int a[81]={0};
    void mu(int k)
    {
       int b[81]={0};
       int i,j;
       for (i=1;i<=a[0];i++) 
       {
         b[i]=b[i-1]/10+a[i]*k;
         b[i-1]=b[i-1]% 10;
       }
       b[0]=a[0];
       while (b[b[0]]>=10)
       {
         b[0]++;
         b[b[0]]=b[b[0]-1]/10;
         b[b[0]-1]=b[b[0]-1] %10;
       }
       for (i=0;i<=b[0];i++)
    	   a[i]=b[i];
    }
    void    divide(int k)
    {
       int b[81]={0};
       int i,j,d=0;
       for (i=a[0];i>=1;i--)
       {
         d=d*10+a[i];
         b[i]=d /k;
         d=d% k;
       }
        b[0]=a[0];
       while (b[b[0]]==0)
    	   b[0]--;
       for (i=0;i<=80;i++) 
    	   a[i]=b[i];
    }
    void plus1() 
    {
       int b[81]={0};
       int len;int i,j;
       if (a[0]>ans[0])
    	   len=a[0];
       else
    	   len=ans[0];
       for (i=1;i<=len;i++) 
       {
        b[i]=b[i-1]/10+a[i]+ans[i];
        b[i-1]=b[i-1]%10;
       }
       b[0]=len;
       while(b[b[0]]>=10)
       {
        b[0]++;
        b[b[0]]=b[b[0]-1] /10;
        b[b[0]-1]=b[b[0]-1] %10;
       }
       for (i=0;i<=b[0];i++) 
    	   ans[i]=b[i];
    }
    int main()
    {
      int i,j,k,m,n;
      int w;
      int jin=1;
      while( scanf("%d%d",&k,&w)!=EOF)
      {
       for (i=1;i<=k;i++) 
    	   
    	   jin=jin*2;
       int len ;
       len=w /k;
       for (i=2;i<=len;i++) 
       {
         for (j=0;j<=80;j++)
    		 a[j]=0;
         a[1]=1;
    	 a[0]=1;
         for (j=1;j<=i;j++) 
         {
          mu(jin-j);
          divide(j);
         }
         plus1();
       }
       if (w % k!=0)
       {    
         int tot=1;
         for (j=1;j<=w % k;j++) 
    		 tot=tot*2;
         tot=tot-1;
         for (i=tot;i>=1;i--)
            if (jin-i-1>=len)
    		{
               for (j=0;j<=80;j++)
    			   a[j]=0;
               a[1]=1;a[0]=1;
               for (j=1;j<=len;j++) 
    		   {
                 mu(jin-i-j);
                 divide(j);
    		   }
               plus1();
    		}
       }
       for (i=ans[0];i>=1;i--) 
    	 printf("%d",ans[i]);
       printf("\n");
      }
      
       return 0;
    }
    

    Pascal :

    const  
     maxn=512;   
    cifang:array [0..10] of longint=(1,2,4,8,16,32,64,128,256,512,1024);   
       
    type  
     arr=array [0..50] of int64;   
      
     var  
     maxlen,n,m:longint;   
    f:array [0..1,0..maxn] of arr;   
    ans:arr;   
       
    procedure init;   
    var  
     i:longint;   
    begin  
     readln(n,m);   
    maxlen:=m div n;   
    for i:=cifang[n]-1 downto 1 do  
     begin  
       f[0,i,0]:=1;   
      f[0,i,1]:=1;   
    end;   
    ans[0]:=1;   
    ans[1]:=0;   
    end;   
      
     function work(x,y:arr):arr;   
    var  
     i,len,t:longint;   
    begin  
     t:=0;   
    fillchar(work,sizeof(work),0);   
    if x[0]>=y[0] then len:=x[0] else len:=y[0];   
    work[0]:=len;    
     for i:=1 to len do   
    begin  
       work[i]:=x[i]+y[i]+t;   
      t:=work[i] div 1000000000;   
      work[i]:=work[i] mod 1000000000;   
    end;   
    if t>0 then  
     begin  
       inc(work[0]);   
      work[work[0]]:=t;   
    end;   
    while (work[work[0]]=0) and (work[0]>1) do dec(work[0]);    
     end;   
      
     procedure main;   
    var  
     i,j,t:longint;   
    begin  
     for i:=1 to maxlen-1 do  
     begin  
       t:=i mod 2;   
      for j:=cifang[n]-1 downto 1 do  
       begin  
        f[t,j]:=work(f[1-t,j+1],f[t,j+1]);   
       ans:=work(ans,f[t,j]);   
      end;   
    end;   
    t:=maxlen mod 2;   
    if m mod n>0 then  
     begin  
       for j:=cifang[n]-1 downto 1 do  
       begin  
        f[t,j]:=work(f[1-t,j+1],f[t,j+1]);   
       if j<=cifang[m mod n]-1 then ans:=work(ans,f[t,j]);      
       end;   
    end;   
    end;   
       
    procedure print(x:arr);   
    var  
     i:longint;   
    begin  
     write(x[x[0]]);   
    for i:=x[0]-1 downto 1 do  
     begin  
       if x[i]<100000000 then write(0);   
      if x[i]<10000000 then write(0);   
      if x[i]<1000000 then write(0);   
      if x[i]<100000 then write(0);   
      if x[i]<10000 then write(0);   
      if x[i]<1000 then write(0);   
      if x[i]<100 then write(0);   
      if x[i]<10 then write(0);   
      write(x[i]);   
    end;   
    writeln;   
    end;   
    
    begin
     init;   
    main;   
    print(ans);   
    end.
    
    • 1

    信息

    ID
    252
    时间
    1000ms
    内存
    125MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者