当前位置:网站首页>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
边栏推荐
- SQL -- data definition
- H. Are You Safe? Convex hull naked problem
- Rust 中的 Cell 共享可变指针
- Unsupervised denoising - [tmi2022] ISCL: dependent self cooperative learning for unpaired image denoising
- [leetcode 350] intersection of two arrays II
- Why does the subscript of the array start from 0 instead of 1?
- Viewer: introduce MySQL date function
- Substring Inversion (Easy Version)
- Sakura substring thinking
- Motor and drive (Qi Jinqing Edition)
猜你喜欢
Automatic control (Han min version)
[leetcode 202] happy number
線性代數第一章-行列式
[leetcode 19] delete the penultimate node of the linked list
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
Contrôle automatique (version Han min)
線性代數第二章-矩陣及其運算
Algèbre linéaire chapitre 2 - matrice et son fonctionnement
Integration and induction of knowledge points of automatic control principle (Han min version)
Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
随机推荐
Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
DBCP usage
Addition, deletion, query and modification of data
电机与拖动(戚金清版)学习整理
Unsupervised denoising - [tmi2022] ISCL: dependent self cooperative learning for unpaired image denoising
Illustrate the significance of hashcode
Linear algebra Chapter 2 - matrices and their operations
Practical operation - Nacos installation and configuration
Custom exception class
程序设计训练
[transfer] MySQL: how many rows of data can InnoDB store in a B + tree?
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi
How to grow at work
St table template
Sakura substring thinking
Advanced operation of idea debug
Mysql database foundation
检测技术与原理
Contrôle automatique (version Han min)
Common programming records - parser = argparse ArgumentParser()