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

想也没想就bfs,MLE,再想得到动规方程

Posted by lmy199433 at 2011-10-17 20:09:26 on Problem 1426 and last updated at 2011-10-17 20:10:17
f[i][j][k].v表示前i位中余数是j的末尾是k的串有没有
f[i][j][k].x表示前i位中余数是j的末尾是k的串是由长度是i-1的串的余数是什么
f[i][j][k].y表示前i位中余数是j的末尾是k的串是由长度是i-1的串的末尾是什么
    cin>>n;
    f[1][1%n][1].v=1;
    flag=0;
    for(int i=1;;i++)
    {
      for(int j=0;j<n;j++)
      {
        for(int k=0;k<2;k++)
        if(f[i][j][k].v)
        {
          if(j==0)
          {
            out(i,j,k);//递归输出
            printf("\n");
            flag=1;
            break;
          }
          f[i+1][j*10%n][0].v=1;
          f[i+1][j*10%n][0].x=j;
          f[i+1][j*10%n][0].y=k;
          f[i+1][(j*10+1)%n][1].v=1;
          f[i+1][(j*10+1)%n][1].x=j;
          f[i+1][(j*10+1)%n][1].y=k;
        }
        if(flag)break;
      }
      if(flag)break;
    }

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