HDU 2110-Crisis of HDU, hdu2110-crisis

Source: Internet
Author: User

HDU 2110-Crisis of HDU, hdu2110-crisis
Crisis of HDUTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 3606 Accepted Submission (s): 1015


Problem Description the last time we talked about the HDU war with Toyo, the result is naturally a Chinese victory. This battle also strengthened the position of Haidong group in the same industry around the world. With the development of the group, the elders in many entrepreneurial periods gradually become retired, first migrating 8600 overseas, and then the linle couple gradually retired from the mountains, at the beginning, only the XHD and Wiskey members were left behind.
In 2020, the company encountered an unprecedented crisis due to its over-expansion and the decrease in the number of mice year by year. At this time, the group had no liquidity. What's more terrible is that at this time, wiskey also decided to quit!
Exiting itself is not troublesome. The trouble is that the exiting person needs to take out the corresponding proportion (1/3) of assets.
Assume that the company has n assets of value at this time, and the number of assets of each value is known. Please help the upset XHD couple calculate the total number of assets to be split.
 
The Input contains multiple test instances. The first line of each instance is an integer n (n <100), indicating a total of n valuable assets, the next n rows contain two integers pi and mi (0 <pi, mi <10), indicating a value and the corresponding quantity respectively. When n is 0, the input is terminated.
 
For each test instance, Output the number of split assets solutions % 10000. If not, Output "sorry", where each instance outputs one row.
 
Sample Input

21 12 10
 
Sample Output
1. Pay attention to step-by-step optimization .. Although I don't think the number of combinations can exceed int ..
#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <string>#include <cctype>#include <vector>#include <cstdio>#include <cmath>#include <deque>#include <stack>#include <map>#include <set>#define ll long long#define maxn 110#define pp pair<int,int>#define INF 0x3f3f3f3f#define max(x,y) ( ((x) > (y)) ? (x) : (y) )#define min(x,y) ( ((x) > (y)) ? (y) : (x) )using namespace std;int n,v[maxn],a[16666],b[16666],num[maxn],p;void solve(){memset(a,0,sizeof(a));a[0]=1;for(int i=0;i<n;i++){for(int j=0;j<=num[i]&&j*v[i]<=p;j++)for(int k=0;k+j*v[i]<=p;k++)b[k+j*v[i]]+=a[k];for(int j=0;j<=p;j++){a[j]=b[j]%10000;b[j]=0;}}if(a[p])printf("%d\n",a[p]%10000);elseputs("sorry");}int main(){    while(~scanf("%d",&n)&&n){p=0;for(int i=0;i<n;i++){scanf("%d%d",&v[i],&num[i]);p+=v[i]*num[i];}if(p%3){puts("sorry");continue;}p/=3;solve();}return 0;}

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.