Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

暴搜

Posted by 814264306 at 2019-07-17 18:32:15 on Problem 1190
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator