当前位置:网站首页>P1586 solution to tetragonal theorem
P1586 solution to tetragonal theorem
2022-04-23 06:29:00 【cornivores】
P1586 The square theorem
The question : The question is very simple .

solution : It is said that this question can be repeated in four cycles + Pruned , The time complexity has to be card by card , The exact solution is dp,dp Dafa is good , Consider with recursion ,dp[j][k] Express j use k The number of schemes represented by the square number , The transfer equation is d p [ j ] [ k ] = ∑ d p [ j − i ∗ i ] [ k − 1 ] dp[j][k]=\sum dp[j-i*i][k-1] dp[j][k]=∑dp[j−i∗i][k−1], Positive order is also useful to the idea of complete knapsack , Pack nine ( Manual funny ).
Code :
#include<bits/stdc++.h>
using namespace std;
const int N = 32768;
const int M = 4e4+10;
const int Mod = 1e9+7;
int dp[M][5];
int main() {
int t, n;
dp[0][0] = 1;
for(int i = 1; i*i <= N; ++i) {
// Enumeration square
for(int j = i*i; j <= N; ++j) {
// Recurrence !!!
for(int k = 1; k <= 4; ++k) {
// Indicates how many squares are selected
dp[j][k] += dp[j-i*i][k-1];
}
}
}
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
int ans = 0;
for(int i = 1; i <= 4; ++i) {
ans += dp[n][i];
}
printf("%d\n", ans);
}
return 0;
}
版权声明
本文为[cornivores]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210615591865.html
边栏推荐
- Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning
- Contrôle automatique (version Han min)
- Best practices for MySQL storage time
- Generate excel template (drop-down selection, multi-level linkage)
- Installation and usage skills of idea
- 程序设计训练
- Addition, deletion, modification and query of MySQL table
- Rust 中的 Cell 共享可变指针
- Programming training
- DBCP usage
猜你喜欢

Techniques et principes de détection
![Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning](/img/21/4bc94fe29f416c936436c04fc16fa8.png)
Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning

C language file operation

Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)

Implementation of displaying database pictures to browser tables based on thymeleaf

Understanding and installing MySQL

Pytorch notes - observe dataloader & build lenet with torch to process cifar-10 complete code

Advanced operation of idea debug

Contrôle automatique (version Han min)

Addition, deletion, query and modification of data
随机推荐
ThreadLocal. Threadlocalmap analysis
Kibana search syntax
lambda expressions
Understanding and installing MySQL
Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
Collections multiple parameter sorting
Failure to deliver XID in Seata distributed transaction project
Framework analysis 2 Source code - login authentication
GNU EFI header file
DBCP usage
Pytorch notes - complete code for linear regression & manual or automatic calculation of gradient code comparison
RPC must know and know
C array
9.Life, the Universe, and Everything
自動控制(韓敏版)
In depth source code analysis servlet first program
[leetcode 954] double pair array
Three ways to create threads
Algèbre linéaire chapitre 2 - matrice et son fonctionnement
Linear algebra Chapter 1 - determinant