Codeforces Round 892 (Div. 2) C. Another Permutation Problem 纯数学方法 思维题

Codeforces Round 892 (Div. 2) C. Another Permutation Problem

源码:

cpp 复制代码
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
const int maxn = 550;
long long s[maxn];

int main(){
	int t;
	cin >> t;
	while(t--){
		long long n;
		cin >> n;
		long long ans = 0;
		s[0] = 0;
		for(long long i = 1;i <= n;i++){
			s[i] = s[i-1]+i*i;
		}
		for(long long i = 1;i <= n;i++){
			long long sum = s[i-1];
			long long maxl = 0;
			long long temp;
			for(long long j = i;j <= n;j++){
				temp = (n-(j-i))*j;
				sum += temp;
				if(temp>maxl){
					maxl = temp;
				}
			}
			sum -= maxl;
			if(sum>ans){
				ans = sum;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
相关推荐
艾醒6 分钟前
大模型原理剖析——解耦RoPE(旋转位置编码)的基本原理
算法
@淡 定9 分钟前
JVM内存区域划分详解
java·jvm·算法
篱笆院的狗14 分钟前
Java 中如何创建多线程?
java·开发语言
疑惑的杰瑞14 分钟前
【C】常见概念
c语言·编译原理
默 语15 分钟前
RAG实战:用Java+向量数据库打造智能问答系统
java·开发语言·数据库
晨晖217 分钟前
二叉树遍历,先中后序遍历,c++版
开发语言·c++
醒过来摸鱼17 分钟前
Java Compiler API使用
java·开发语言·python
M__3319 分钟前
动规入门——斐波那契数列模型
数据结构·c++·学习·算法·leetcode·动态规划
wangchen_021 分钟前
C/C++时间操作(ctime、chrono)
开发语言·c++
Dev7z32 分钟前
基于MATLAB HSI颜色空间的图像美颜系统设计与实现
开发语言·matlab