problem url: http://acm.timus.ru/problem.aspx?space=1&num=1044
This issue require some math trick, we shoud use "Permutations" here:
#include
<
cstdio
>
#include
<
iostream
>

#define
MAX_SUM 36

using
namespace
std;

void
main()
...
{
int n = 1;
int hn =1;
int count =0;
int temp= 0;
int tsum =0;
int sumdb[MAX_SUM+1];
memset(sumdb, 0, sizeof(int) * (MAX_SUM+1));
cin>> n;
hn = n/2;
int i=0;
int j= 0;
int ub = 1;
for(i=0;i<hn;++i) ub*=10;
for(i=0;i<ub;++i)
...{
tsum = 0;
temp = i;
for(j=0;j<hn;++j)
...{
tsum += temp%10;
temp /= 10;
}
sumdb[tsum]++;
}
for(i=0;i<MAX_SUM+1;++i)
...{
if(sumdb[i]>0)
...{
count += (sumdb[i]*(sumdb[i]-1) + sumdb[i]);
}
}
cout<< count;
}
本文介绍了一个使用C++实现的算法问题解决方案,该问题要求计算在给定数字长度下,所有可能数字组合中数位和相同的不同整数对的数量。通过使用循环和数组来遍历所有可能的整数并计算数位之和,然后利用排列组合原理得出最终答案。
419

被折叠的 条评论
为什么被折叠?



