2014 Super training #9 c e-cup 2 -- memory-based search

Source: Internet
Author: User

Original question: zoj 3681 http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 3681.

Question: Give m, n, m to m people. You can divide m people into k groups. M/k people in each group should have the same number of people, if more than half of the groups support Italy, all N of them support Italy. at the same time, we can further divide any or multiple groups in the K group, assuming that M/K is further divided into P groups, if more than half of P groups support Italy, M/K supports Italy, and so on. Given that N people support Italy, ask if it seems that all m people support Italy. And the minimum number of people required to support Italy is required to ensure that all m people support Italy.

Practice: DFS appears that m people support the minimum number of Italy people, and then compare it with N. If res <= N, the number can be reached. Otherwise, the number cannot be reached.

When DFS is used, enumerate its approximate number (because it should be divided into groups with the same number of people), and then divide it to DFS.

Code:

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <map>using namespace std;#define N 1007std::map<int, int> ans;int DFS(int m){    if(ans.count(m))        return ans[m];    int mini = m/2+1;    for(int i=2;i*i<=m;i++)    {        if(m%i == 0)        {            mini = min(mini,((m/i)/2+1)*DFS(i));            mini = min(mini,(i/2+1)*DFS(m/i));        }    }    ans[m] = mini;    return ans[m];}int main(){    int n,m;    ans.clear();    while(scanf("%d%d",&m,&n)!=EOF)    {        int res = DFS(m);        if(res <= n)            puts("Yes");        else            puts("No");        printf("%d\n",res);    }    return 0;}
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.