当前位置:网站首页>Number of square arrays (day 81)
Number of square arrays (day 81)
2022-07-27 03:40:00 【Zhangxueheng】
List of articles
1: subject
Given an array of nonnegative integers A, If the sum of each pair of adjacent elements in the array is a complete square , This array is called a square array .
return A The number of squares arranged by .
Two permutations A1 and A2 Different if and only if there is an index i, bring A1[i]≠A2[i].
Input format
The first line contains an integer n, Represents an array A The length of .
The second line contains n It's an integer A[i].
Output format
An integer , Express A The number of squares arranged by .
Data range
1≤n≤12,
0≤A[i]≤109.
sample input :
3
1 17 8
sample output :
2
Sample explanation
[1,8,17] and [17,8,1] They're all effective permutations .
2: Code implementation
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 15;
int n;
int w[N];
bool st[N];
int ans;
bool check(int x)
{
int r = sqrt(x);
return r * r == x;
}
void dfs(int u, int last)
{
if (u == n) ans ++ ;
else
{
for (int i = 0; i < n; i ++ )
{
if (st[i]) continue; // Used
if (i && !st[i - 1] && w[i] == w[i - 1])
continue;
if (!check(last + w[i])) continue;
st[i] = true;
dfs(u + 1, w[i]);
st[i] = false;
}
}
}
int main()
{
cin >> n;
for (int i = 0; i < n; i ++ ) cin >> w[i];
sort(w, w + n);
for (int i = 0; i < n; i ++ )
if (!i || w[i] != w[i - 1])
{
st[i] = true;
dfs(1, w[i]);
st[i] = false;
}
cout << ans << endl;
return 0;
}
边栏推荐
- Add support for @data add-on in idea
- Insert pictures and videos in typera
- docker 创建mysql 8.x容器,支持mac ,arm架构芯片
- 【无标题】JDBC连接数据库读超时
- flask_restful中reqparse解析器继承
- 网络安全/渗透测试工具AWVS14.9下载/使用教程/安装教程
- Penetration test - post penetration - Trace cleaning
- Redis source code learning (33), command execution process
- [1206. Design skip table]
- Csu18m91 is used as the master controller of the intelligent scale scheme
猜你喜欢

Mysql: summary of common sub database and sub table schemes of Internet companies

Introduction to database - a brief introduction to MySQL

Win10/win11 lossless expansion of C disk space, cross disk consolidation of C and e disks

Spark Learning Notes (VI) -- spark core core programming RDD action operator

数字孪生实际应用:智慧城市项目建设解决方案

MySQL Chinese failure

477-82(236、61、47、74、240、93)

Explain详解

How many implementation postures of delay queue? Daily essential skills!

Network security / penetration testing tool awvs14.9 download / tutorial / installation tutorial
随机推荐
redis入门练习
MySQL has a nonexistent error
How to conduct 360 assessment
The diagram of user login verification process is well written!
mysql如何优化
Spark Learning Notes (VI) -- spark core core programming RDD action operator
“满五唯一”和“满二唯一”是什么?有什么不同?
Mysql database related operations
[flask] the server obtains the request header information of the client
It's too strong. An annotation handles the data desensitization returned by the interface
在typora中插入图片和视频
Add support for @data add-on in idea
The function and application of lpci-252 universal PCI interface can card
Details of impala implementation plan
spark学习笔记(六)——sparkcore核心编程-RDD行动算子
mysql底层数据结构
flask_restful中reqparse解析器继承
Practice of online problem feedback module (XV): realize the function of online updating feedback status
Basic concept and essence of Architecture
Network security / penetration testing tool awvs14.9 download / tutorial / installation tutorial