标签:
题目链接:
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <map> using namespace std; typedef long long ll; const ll mod=1e9+7; const ll inf=1e15; const int N=1e5+6; int n; ll dp[N],f[N]; void fun() { dp[1]=1;//注意dp[1] dp[2]的初始化,我在这里就wa了一发; dp[2]=2; dp[3]=3; f[1]=1; for(int i=2;i<N;i++) { ll x=(i); f[i]=f[i-1]+x*(x+1)/2; } for(int i=4;i<N;i++) { dp[i]=dp[i-1]+1+f[i-3]; } } int main() { int t; scanf("%d",&t); fun(); while(t--) { scanf("%d",&n); cout<<dp[n]<<"\n"; //printf("%lld\n",dp[n]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhangchengc919/p/5428730.html