当前位置:网站首页>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;
}
边栏推荐
- Introduction to database - Introduction to database
- It's too strong. An annotation handles the data desensitization returned by the interface
- 架构基本概念和架构本质
- Comprehensive care analysis lyriq Ruige battery safety design
- Technology vane | interpretation of cloud native technology architecture maturity model
- Graphic SQL, this is too vivid!
- MySQL underlying data structure
- How can you access the domestic server and overseas server quickly with one database?
- How to design the red table of database to optimize the performance
- Docker creates MySQL 8.x container and supports Mac and arm architecture chips
猜你喜欢

How to optimize MySQL

基于OpenCV的轮廓检测(2)

复盘:DFS与BFS的主要区别,在思想上的区别,代码实现上的区别

mysql底层数据结构

Deployment of ruoyi's environment and operation of the system
![[tree chain dissection] 2022 Hangzhou Electric Multi school 21001 static query on tree](/img/b3/58c053d082807a0e5639e5b968aa20.png)
[tree chain dissection] 2022 Hangzhou Electric Multi school 21001 static query on tree

Practical application of digital twins: smart city project construction solution

Spark Learning Notes (V) -- spark core core programming RDD conversion operator

Redis spike case, learn from Shang Silicon Valley teacher in station B

数字孪生实际应用:智慧城市项目建设解决方案
随机推荐
Add support for @data add-on in idea
若依框架代码生成详解
Explain tool actual operation
代码审查金字塔
spark:地区广告点击量排行统计(小案例)
Spark Learning Notes (V) -- spark core core programming RDD conversion operator
【学习笔记之菜Dog学C】字符串+内存函数
微信小程序生成Excel
百融榕树数据分析拆解方法
Safe-arc/warner power supply maintenance xenon lamp power supply maintenance analysis
Network security / penetration testing tool awvs14.9 download / tutorial / installation tutorial
Comprehensive care analysis lyriq Ruige battery safety design
Penetration test - post penetration - Trace cleaning
How to conduct 360 assessment
Contour detection based on OpenCV (2)
opiodr aborting process unknown ospid (21745) as a result of ORA-609
flask_ Reqparse parser inheritance in restful
[flask] the server obtains the file requested by the client
Sqlserver select * can you exclude a field
Does Oracle have a distributed database?