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

这种题怎么才这么几个人ac

Posted by zhangxiao1124 at 2008-05-01 17:07:25 on Problem 2205
#include<iostream>
using namespace std;
#define maxn 2005
int k,n,m,a[maxn],ans[maxn][maxn];

void Dfs(int dep,int sum) {
    if (dep>n) {
        if (a[n] || n==1) {
            m++;
            for (int i=1; i<=n; i++) ans[m][i]=a[n+1-i];
        }
        return;
    }
    for (a[dep]=0; a[dep]<k; a[dep]++) {
        int tot=0;
        for (int i=1; i<=dep; i++) {
            int j=dep+1-i;
            tot+=a[i]*a[j];
        }
        if ((tot+sum)%k==a[dep]) Dfs(dep+1,(tot+sum)/k);
    }
}

inline char Change(int x) {
    if (x<=9) return '0'+x;
    return 'A'+x-10;
}

void Print() {
    printf("%d\n",m);
    for (int i=1; i<=m; i++) {
        for (int j=1; j<=n; j++) printf("%c",Change(ans[i][j]));
        printf("\n");
    }
}

int main() {
    scanf("%d%d",&k,&n);
    Dfs(1,0);
    Print();
    return 0;
}

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