1 solutions
-
0
这题可以使用数论,我这里用dp去解决
#include<bits/stdc++.h> typedef long long LL; using namespace std; const int N = 30; int dp[N][N],n; /* 这里dp[i][j]当中 i 表示不大于i,j表示排列排j个,即dp[4][3] 就是最大数是 4,取三个来排 dp[4][3] = 8,dp[4][2] = 12,dp[4][4] = 2; 最后加起来就是答案 */ int main () { cin >> n; for(int j = 1;j <= n;++ j) { for(int i = 1;i <= n;++ i) { if(j == 1)dp[i][j] = i * 2;//这里将所有dp[i][1]变成2 * i; else dp[i][j] = dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];//状态转移方程; } } LL ans = 0; for(int i = 2;i <= n;++ i) { ans += dp[n][i]; } cout << ans; return 0; }
Information
- ID
- 1183
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 8
- Tags
- # Submissions
- 31
- Accepted
- 5
- Uploaded By