标签:
Description
Input
Output
Sample Input
2 1 2
Sample Output
2 7
这道题看了题解才写出来,有两种做法。
#include<cstdio> #include<cstring> #include<iostream> #include<stdlib.h> #include<vector> #include<queue> #include<cmath> using namespace std; #define maxn 10010 #define oo 0x3f3f3f int n; int k; long long dp[maxn]; void init() { for(int i=3; i<=maxn; i++) dp[i] = ((i-1)*2-1)*2 + dp[i-1]+3; } int main() { int t,m; scanf("%d",&t); while(t--) { scanf("%d",&m); dp[1] = 2; dp[2] = 7; init(); printf("%I64d\n",dp[m]); } return 0; }///用递推来写
#include<cstdio> #include<cstring> #include<iostream> #include<stdlib.h> #include<vector> #include<queue> #include<cmath> using namespace std; #define maxn 10010 #define oo 0x3f3f3f int n; int k; long long dp[maxn]; int main() { int t; long long m; scanf("%d",&t); while(t--) { scanf("%I64d",&m); printf("%I64d\n",2*m*m-m+1); } return 0; }
标签:
原文地址:http://www.cnblogs.com/biu-biu-biu-/p/5744508.html