hdu 2519

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2519

原来可以有递推公式的。。。c[n][m]=c[n-1][m]+c[n-1][m-1];

orz。。。自己搞了个阶乘。。。orz。。。还用string来处理了。。小题大做了。。。

View Code
 1 #include<iostream>
 2 #include<algorithm>
 3 #include<string>
 4 #include<vector>
 5 using namespace std;
 6 vector<string>vet;
 7 
 8 string facs(const string &str,int num){
 9     int len=str.size();
10     int c=0,l=0;
11     string s="";
12     for(int i=len-1;i>=0;i--){
13         c=l+(str[i]-'0')*num;
14         s+=c%10+'0';
15         l=c/10;
16     }
17     while(l){
18         s+=l%10+'0';
19         l/=10;
20     }
21     reverse(s.begin(),s.end());
22     return s;
23 }
24 
25 void Initiate(){
26     vet.push_back("0");
27     vet.push_back("1");
28     vet.push_back("2");
29     string str="2";
30     for(int i=3;i<=31;i++){
31         str=facs(str,i);
32         vet.push_back(str);
33     }
34 }
35 
36 string Divide(const string &s1,int n){
37     string s="";
38     int len=s1.size();
39     int c=0,l=0;
40     for(int i=0;i<len;i++){
41         c=l*10+s1[i]-'0';
42         l=c%n;
43         c=c/n;
44         if(c==0&&s.size()==0)continue;
45         else s+=c+'0';
46     }
47     return s;
48 }
49 
50 
51 
52 int main(){
53     Initiate();
54     int _case;
55     scanf("%d",&_case);
56     while(_case--){
57         int n,m;
58         scanf("%d%d",&n,&m);
59         if(n==m){
60             printf("1\n");
61         }else if(n<m){
62             printf("0\n");
63         }else {
64             string s1=vet[n];
65             for(int i=2;i<=m;i++){
66                 s1=Divide(s1,i);
67             }
68             for(int i=2;i<=(n-m);i++){
69                 s1=Divide(s1,i);
70             }
71             cout<<s1<<endl;
72         }
73     }
74     return 0;
75 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值