A Claire_ 's problem 第八届北京邮电大学程序设计竞赛 - 热身赛 (2)

时间限制 5000 ms  内存限制 65536 KB

题目描述

As we all know,Claire_ and ykwd are famous ACMers in BUPT ACM Group.They always play games together.Nowadays they play such a game:at first,Claire_ writes down a number,and then she selects a special digit(from 0 to 9),she removes all the special digits,then she get a group of non-special digits.Claire_ can use the group of non-special digits and limitless special digit to create new numbers.She is interested in how many positive numbers she create are less than the former number.She asks ykwd to solve this problem as soon as possible,otherwise ykwd would stand on his knees on the keyboard.Be notice leading zeros are not allowed.

输入格式

At first line,there is a number T  which is the number of cases;
For each case,there is a number  N  ( length  1000 ) and a digit(from 0 to 9).

输出格式

For each case,you should print the answer in one line.Because the answer can be so large that you should print the answer mod 20130303.

输入样例

3
1020 0
1020 1
2110 1

输出样例

7
2
13

用例:

输入:777 7

输出:2



组合数学。

special digit为x.

设原数字长度是 n;

 则重组后的长度小于n的数肯定小于原数,这些数就是由 non-special digits 和 i(0<=i<=《special digit的个数》)个special digit组成;

可用排列组合算;假如求由  111333322222 的任意组合可组成数的个数,相当于3个A球,4个B球,5个C球放入12个盒子里,每个盒子放一个球。

答案为C(12,3)*C(9,4)*C(5,5); 求时注意一下没有前缀0;

还有就是所有的位数都用,长度为n,这时要保证组成的数小于原数,

设这个数为736890987,如果第一位取1--6(注意前缀0),后面的数是可以任意取的,用上面的方法算一下; 如果第一位为7,第二位只能取不超过3的数,第二位去0--2时,后面可任意取;第二位取3时,第三为只能取不超过6的数……,有点数位dp 不能超过上界的意思;然后一直加到末位。。



#include<stdio.h>    
#include<string.h>    
#include<math.h>    
#include<stdlib.h>    
#include<iostream>  
#include<algorithm>  
#include<queue>  
#include<vector>  
using namespace std;  
#define ll long long  
#define inf 0x3f3f3f3f  
#define N 1010  
  
char ch[1010];  
int p[1010];  
int bit[10];  
ll mod=20130303;  
  
ll c[N][N];  
int x;  
ll C(ll n,ll k)      
{      
    if(c[n][k]!=-1) return c[n][k];      
    if(k==1) return c[n][k]=n;      
    if(k==0) return c[n][k]=1;      
    if(n==k) return 1;      
    if(k > (n>>1)) return c[n][k]=C(n,n-k);      
    return c[n][k]=(C(n-1,k-1)+C(n-1,k))%mod;      
}   
ll calc(ll sum,ll n)  
{  
    int i;  
    ll ans=1;  
	int ff=0;
    for(i=0;i<10;i++)  
    {  
        if(i!=x && bit[i]==0) continue;  
        if(i==x && n==0) continue;  
		ff=1;
        if(i!=x){  
            if(i==0){  
                sum--;  
                ans=(ans*C(sum,bit[i]))%mod;  
                sum-=bit[i];  
                sum++;  
            }  
            else{  
                ans=(ans*C(sum,bit[i]))%mod;  
                sum-=bit[i];  
            }  
        }  
        else{  
            if(i==0){  
                sum--;  
                ans=(ans*C(sum,n))%mod;  
                sum-=n;  
                sum++;  
            }  
            else{  
                ans=(ans*C(sum,n))%mod;  
                sum-=n;  
            }  
        }  
    }  
	if(ff==0) return 0;
    return ans;  
}  
ll com(ll sum)  
{  
    ll ans=1;  
    int i;  
    for(i=0;i<10;i++)  
    {  
        if(!bit[i]) continue;  
        ans=(ans*C(sum,bit[i]))%mod;  
        sum-=bit[i];  
    }  
    return ans;  
}  
int main()  
{  
    int t,i,j,k;  
    cin>>t;  
    memset(c,-1,sizeof(c));  
    while(t--)  
    {  
        scanf("%s%d",ch,&x);  
        int len=strlen(ch);  
        memset(bit,0,sizeof(bit));  
        for(i=0;i<len;i++){  
            bit[ch[i]-'0']++;  
            p[i]=ch[i]-'0';  
        }  
        ll sum=0;  
        for(i=0;i<10;i++)  
            if(i!=x) sum+=bit[i];  
        ll ans=0;  
        for(i=0;i<bit[x];i++)  
        {  
            ans=(ans+calc(sum+i,i))%mod;  
        }  
        sum+=bit[x];  
        for(i=0;i<len;i++)  
        {  
            for(j=0;j<p[i];j++)  
            {  
                if(i==0 && j==0) continue;  
                if(!bit[j]) continue;  
                bit[j]--;  
                ans=(ans+com(sum-1-i))%mod;  
                bit[j]++;  
            }  
            bit[p[i]]--;  
        }  
        cout<<ans<<endl;  
    }  
}  




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,"npm ERR! A complete log of this run can be found in: C:\Users\Claire\AppData\Local\npm-cache\_logs\2023-09-01T08_13_13_526Z-debug-0.log" 是错误信息的一部分,它提供了一个完整的日志文件路径,可以在此路径下找到详细的运行日志记录。 如果您遇到了 "Node.js is only supported on Windows 8.1, Windows Server 2012 R2, or higher" 的错误信息,您可以尝试重新运行node命令,并设置NODE_SKIP_PLATFORM_CHECK环境变量为1,以跳过平台检查。请注意,这样做可能导致Node.js无法正确执行,并且在不受支持的平台上遇到的任何问题都不会修复。 另外,引用中提到的路径 "C:\Users\mac\AppData\Roaming\npm\node_modules\node\bin" 是一个文件路径,其中包含一个名为"node"的文件,内容是"This file intentionally left blank"。这个文件似乎是被无缘无故地多出来的。 综合来看,如果您遇到了npm ERR!的错误信息,建议查看完整的日志文件以获取更详细的错误信息。另外,如果在不受支持的平台上使用Node.js时出现问题,可以尝试设置NODE_SKIP_PLATFORM_CHECK环境变量为1,但需要注意可能会导致Node.js无法正常工作。最后,如果出现了无缘无故多出的文件"node",你可以考虑删除它或者进一步调查为什么会出现这个文件。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [npm ERR! code EPERM npm ERR! syscall open npm ERR! path C:\Program Files\nodejs\node_cache\_cacache\](https://download.csdn.net/download/weixin_38663701/14040568)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [C:\Users\mac\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found](https://blog.csdn.net/qq285744011/article/details/122849479)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值