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;
}
相关推荐
LYS_06182 分钟前
寒假学习(5)(C语言5+模数电5)
c语言·学习·模数电
2501_941982055 分钟前
Java 分布式环境下的 Access_Token 一致性方案:如何避免多节点冲突?
java·开发语言·分布式
历程里程碑14 分钟前
哈希3 : 最长连续序列
java·数据结构·c++·python·算法·leetcode·tornado
闻缺陷则喜何志丹16 分钟前
【图论】P9661 [ICPC 2021 Macao R] Sandpile on Clique|普及+
c++·算法·图论·洛谷
chilavert31817 分钟前
技术演进中的开发沉思-328 JVM:垃圾回收(上)
java·开发语言·jvm
qq_3975623118 分钟前
Qt_工程执行逻辑_窗口逻辑
开发语言·qt
hoiii18720 分钟前
基于MATLAB的Kriging代理模型实现与优化
开发语言·matlab
火云洞红孩儿20 分钟前
2026年,用PyMe可视化编程重塑Python学习
开发语言·python·学习
2401_8414956421 分钟前
【LeetCode刷题】两两交换链表中的节点
数据结构·python·算法·leetcode·链表·指针·迭代法
2501_9445215927 分钟前
Flutter for OpenHarmony 微动漫App实战:标签筛选功能实现
android·开发语言·前端·javascript·flutter