竞赛
考级
本来想用贪心的,但发现大弹射过后还有小弹射,所以只能上动态规划了
队团加不)ด้้童帅_者仇复
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
anyin775 请回关
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; int a[n]; a[1]=0; for (int i = 2; i <= n; i++) { a[i] = i - 1; for (int j = 2; i - j * j >= 1; j++) { a[i] = min(a[i], a[i - j * j] + j + 1); } } cout << a[n]; return 0; }
cat