Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
暴搜#include<iostream> #include<math.h> using namespace std; int n, m; int ans; int dfs(int hi, int ri, int v,int s,int c) { if (v == n&&c==0) {if (ans > s)ans = s;return 1;} else if (c <= 0) {return 0;} else if (v >= n) {return 0;} else if (s >= ans) {return 0;} else { int nnow = n - v; for (int i = ri-1; i >= c; i--) { if (c != m) { int ss = ans - s; int sb = 2 * (n - v) / i; if (sb > ss) { break; } } for (int j = hi-1 ; j >= c; j--) { int v1 = j*i*i; int s1 = 2 * i*j; if (c == m) { s1 += i*i; } dfs(j, i, v+v1, s+s1, c-1); } } return 0; } } int main() { ans = 9999999; cin >> n >> m; dfs(10000, 100, 0, 0, m); if (ans == 9999999)ans = 0; cout << ans << endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator