--正文
递推题,通过找关系即可列出递推式
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; #define SIZE 10 typedef long long LL; LL f[SIZE+1][SIZE+1] = {0}; LL pow2[20] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096}; int main(){ int i,j; int time,T; scanf("%d",&T); int n,m; for (time=1;time<=T;time++){ scanf("%d %d",&n,&m); memset(f,0,sizeof(f)); f[1][1] = 1; for (i=2;i<=n;i++){ f[1][i] = f[1][i-1] + i; // printf("%d %d %lld\n",1,i,f[1][i]); } for (i=2;i<=m;i++){ f[i][n] = f[i-1][n] + n*(n+1)*i/2; //printf("%d %d %lld\n",i,n,f[i][n]); } printf("%lld\n",f[m][n]); } }