[Luo] valley P2518 [HAOI2010] count (full set of re-arrangement simple count +)

Here Insert Picture Description
Ideas: For small numbers than the current length of the digital preamble can be regarded as 0 is actually, for example, 1230 and 123, in fact, can be seen as mesh 1230,0123 this topic would be simplified full array of length n in number in a small number. The current number. First, introduce re-set the whole arrangement of how to find, look at what I understand, a little ugly word the only Ren Ren. . .
Here Insert Picture Description
So how do we find the key to re-set the whole arrangement is less than the number of the current number of it? No matter how this fact with the idea of digital DP, and set the current number of X, we can enumerate X every one, assuming that the current is i, then if the current bit is [0, i-1] words are not behind the arrangement will be smaller than X, so the general idea is to go through each and every X, and then traverse less than all of the current number (ie [0, i]) i of them were re-set the whole arrangement of computing, the answer is accumulated on the line but the number is to note some of the details of each number on the line, so can be more than code.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=50;
ll c[maxn][maxn],cnt[maxn],ans;
char s[maxn];
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	for(int i=1;i<=len;++i) cnt[s[i]-'0']++;
	c[0][0]=c[1][0]=c[1][1]=1;
	for(int i=2;i<maxn;++i)
	{
		c[i][0]=1;
		for(int j=1;j<maxn;++j)
		c[i][j]=c[i-1][j]+c[i-1][j-1];
	}
	for(int i=1;i<=len;++i)
	{
		for(int j=0;j<s[i]-'0';++j)
		{
			if(cnt[j]>=1)
			{
				ll res=1;
				int sum=len-i;
				cnt[j]--;//要注意的就是这个地方,我们要先把这个数拿出来才能计算
				for(int k=0;k<10;++k) res*=c[sum][sum-cnt[k]],sum-=cnt[k];
				cnt[j]++;//最后加回去变回原样
				ans+=res;
			}
		}
		cnt[s[i]-'0']--;
	}
	printf("%lld\n",ans);
 } 
Published 70 original articles · won praise 0 · Views 2444

Guess you like

Origin blog.csdn.net/qq_42479630/article/details/104149480