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;
}
相关推荐
傻乐u兔3 小时前
C语言进阶————指针4
c语言·开发语言
大模型玩家七七3 小时前
基于语义切分 vs 基于结构切分的实际差异
java·开发语言·数据库·安全·batch
历程里程碑3 小时前
Linux22 文件系统
linux·运维·c语言·开发语言·数据结构·c++·算法
牛奔4 小时前
Go 如何避免频繁抢占?
开发语言·后端·golang
寻星探路8 小时前
【深度长文】万字攻克网络原理:从 HTTP 报文解构到 HTTPS 终极加密逻辑
java·开发语言·网络·python·http·ai·https
lly2024069 小时前
Bootstrap 警告框
开发语言
2601_9491465310 小时前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API
c语言·开发语言
你撅嘴真丑10 小时前
第九章-数字三角形
算法
曹牧10 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
KYGALYX10 小时前
服务异步通信
开发语言·后端·微服务·ruby