Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <numeric>
- #include <cmath>
- using namespace std;
- #define FOR(i,a,b) for(int i=(a);i<(b);i++)
- const int MAX_SUM = 20 * (9*9);
- bool isSquare[MAX_SUM + 1];
- bool isGood(vector<int>& cnt){
- int sum = 0;
- FOR(d,0,10) sum += cnt[d] * d * d;
- return isSquare[sum];
- }
- long long doit(vector<int>& cnt){
- if( accumulate(cnt.begin(), cnt.end(), 0) == 20 ){
- return isGood(cnt) ? 1 : 0;
- }
- long long ret = 0;
- FOR(d,0,10){
- cnt[d]++;
- ret += doit(cnt);
- cnt[d]--;
- }
- return ret;
- }
- int main(){
- for( int n = 0; n*n <= MAX_SUM; n++ ) isSquare[n*n] = true;
- vector<int> cnt(10, 0);
- cout << doit(cnt) << endl;
- }
Add Comment
Please, Sign In to add comment