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;
}
相关推荐
星夜离尘5620 小时前
MATLAB 线性去趋势为何损伤低频正弦:联合最小二乘估计幅相与漂移
开发语言·matlab
Zwawa21 小时前
让电机走到指定位置:编码器位置环 PID
c语言·单片机·嵌入式
倚楼听风语21 小时前
Kotlin 协程与 suspend 原理详解
java·算法·kotlin
程序员清风21 小时前
双指针与滑动窗口:高效处理连续区间
开发语言·算法
代钦塔拉21 小时前
【C++/Qt 进阶】设计模式系列(2):工厂模式——从游戏角色到披萨店
c++·算法·设计模式
思茂信息21 小时前
电磁仿真学涉及哪些算法?
人工智能·算法·数学建模·matlab·emc·电磁仿真·仿真辐射
开开心心就好21 小时前
文件被占用删不掉?解锁工具强制删除
java·运维·服务器·开发语言·前端·pdf·ocr
糖果豆豆21 小时前
让 AI 自查三遍,它只会把错的说得更像对的——检查的人和被检查的,是同一个
算法·架构
云和数据.ChenGuang21 小时前
python大小整数范围解析
java·开发语言·python
fensnote1 天前
西门子 S7 PLC 内部寄存器读写 Demo(C 语言)
c语言·开发语言