ADD Again
Input: standard input
Output: Standard Output
Summation of sequence of integers are always a common problem in computer science. Rather than computing blindly, some intelligent techniques make the task simpler. Here is the summation of a sequence of integers. The sequence is an interesting one and it are the all possible permutations of a given set of digits. For example, if the digits is <1 2 3>, then six possible permutations is <123>, <132>, <213>, &L T;231>, <312>, <321> and the sum of them is 1332.
Input
Each input set would start with a positive integern (1≤n≤12). The next line would contain N decimal digits. Input would be terminated by n=0. There'll is at the most 20000 test set.
Output
For each test set, there should is a one line output containing the summation. The value would fit in 64-bit unsigned integer.
Sample input Output for sample input
Problemsetter:md. Kamruzzaman
Special Thanks:shahriar Manzoor
/* Test instructions probably is to give you n number, with this n number can compose M integer, for m integer and this problem knowledge point is a repeating element of the total number of elements: there are k elements, including the first element I have NI, perfection permutation number: The number of =n!/(N1!*n2!*n3!*n4!.... *nk!) Figure out each number of times each position, and then add up on the PS: This problem will be a long long to use unsigned long long, seemingly UVA before the problem often has this kind of egg pain ah */
#include <stdio.h> #include <string.h> #define LL unsigned long longint a[10];//The topic is not very clear, is the number between 0-9; int b[15]; LL jie[15];int n;void init () { jie[0]=1; for (LL i=1;i<15;i++) { jie[i]=i*jie[i-1]; }} int main () { freopen ("Add.txt", "R", stdin); LL ANS,SUM,TP; Init (); while (scanf ("%d", &n), N) { sum=0; memset (A,0,sizeof (a)); for (int i=0;i<n;i++) { int tp; scanf ("%d", &TP); a[tp]++; SUM+=TP; } Ans=jie[n-1]*sum; for (LL i=0;i<10;i++) { if (A[i]) Ans/=jie[a[i]]; } LL kk=0; for (int i=1;i<=n;i++) { kk=kk*10+ans; } printf ("%llu\n", KK); } return 0;}
all permutations = (n-1)!/(n1!* N2!*n3!*n4!.. (ni-1)!.. *nk!) Figure out the number of times each position is counted, and then multiply I to add up the contribution value of the I element
#include <stdio.h> #include <string.h> #define LL unsigned long longint a[10];//The topic is not very clear, is the number between 0-9; int b[15]; LL jie[15];int n;void init () {jie[0]=1; for (LL i=1;i<15;i++) {jie[i]=i*jie[i-1]; }}ll Chsort (ll x) {ll cnt=1; for (int i=0;i<10;i++) {if (A[i]) {if (i==x) cnt*=jie[a[i]-1]; else Cnt*=jie[a[i]]; }} return cnt;} int main () {//Freopen ("Add.txt", "R", stdin); LL ans,sum; Init (); while (scanf ("%d", &n), N) {sum=0; memset (A,0,sizeof (a)); for (int i=0;i<n;i++) {int tp; scanf ("%d", &TP); a[tp]++; Sum+=b[i]; } ans=0; Ans=jie[n-1]*sum; for (LL i=0;i<10;i++) {if (A[i]) {ans+=jie[n-1]*i/chsort (i); }} LL kk=0; for (int i=1;i<=n;i++) {Kk=kk*10+ans; } printf ("%llu\n", KK); } return 0;}
Add Again (repeating element sort)