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;
}
相关推荐
电商API_180079052477 分钟前
淘宝天猫商品数据爬取方案:官方API与非官方接口对比
linux·服务器·开发语言·前端·爬虫·python·数据挖掘
mxpan15 分钟前
golang 一种并发安全 map 的实现
开发语言·golang
dying_man24 分钟前
LeetCode--32.最长有效括号
算法·leetcode
漫无目的行走的月亮28 分钟前
微信小程序,微信授权手机号码
开发语言·javascript·ecmascript
我命由我1234529 分钟前
Android 开发问题:CardView 的阴影效果会受到父容器的裁切
android·java·开发语言·java-ee·android studio·android-studio·android runtime
G等你下课32 分钟前
Leetcode491. 非递减子序列
算法
追风赶月、1 小时前
【QT】控件二(输入类控件、多元素控件、容器类控件与布局管理器)
开发语言·qt
API_technology1 小时前
亚马逊 API 实战:商品详情页实时数据采集接口开发与调用
大数据·开发语言·python·数据挖掘
vhgcc1 小时前
在 Java 中使用 Apache Tika 读取 doc、docx等格式文件内容
java·开发语言·自然语言处理·apache·ai编程
Georgewu12 小时前
【AI大模型入门指南】提示词Prompt工程详解
算法·aigc·ai编程