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;
}
相关推荐
kill bert2 小时前
Java八股文背诵 第四天JVM
java·开发语言·jvm
√尖尖角↑2 小时前
力扣——【1991. 找到数组的中间位置】
算法·蓝桥杯
Allen Wurlitzer2 小时前
算法刷题记录——LeetCode篇(1.8) [第71~80题](持续更新)
算法·leetcode·职场和发展
低头专研3 小时前
Markdown标题序号处理工具——用 C 语言实现
c语言·开发语言·typora·markdown文件标题编号·md文件标题序号
百锦再4 小时前
五种常用的web加密算法
前端·算法·前端框架·web·加密·机密
刚入门的大一新生5 小时前
C++初阶-C++入门基础
开发语言·c++
你是理想5 小时前
wait 和notify ,notifyAll,sleep
java·开发语言·jvm
碳基学AI5 小时前
北京大学DeepSeek内部研讨系列:AI在新媒体运营中的应用与挑战|122页PPT下载方法
大数据·人工智能·python·算法·ai·新媒体运营·产品运营
forestsea5 小时前
Python进阶编程总结
开发语言·python·notepad++
q567315235 小时前
使用Java的HttpClient实现文件下载器
java·开发语言·爬虫·scrapy