[Swust OJ 234]--irreduciblenumber (test instructions Tai Keng)

Source: Internet
Author: User

Title Link: http://acm.swust.edu.cn/problem/0234/

Time limit (ms): Memory Limit (KB): 65535 descriptionyou is given a list of number. An integer K was irreducible with respect to the numbers if K cannot be represented as
A sum of one or more elements from the numbers, where each element of the numbers is used at most once. Return
The smallest positive integer that's irreducible with respect to the given numbers. Inputn:the size of the numbers,-1 indicates end. (1 =< n <= 3)
Next line contains n numbers (1 =< number <=) outputthe smallest positive integers that's irreducible with Respe CT to the given numbers. Sample Input
21 121 2-1

Sample Output
34



scpc__ Zhang Jian topic: Test instructions is such, input n (n!=-1), the next n number, all these numbers and their addition can be obtained by the number is not used, starting from 1, the smallest number of outputs can be used to output ~ ~ ~ Code as follows: Due to a maximum of 3
1#include <iostream>2 using namespacestd;3 inta[5], vis[301];4 intMain () {5     intn, I;6      while(Cin >> N, n! =-1){7memset (Vis,0,sizeof(Vis));8          for(i =1; I <= N; i++){9CIN >>A[i];TenVis[a[i]] =1; One         } A         if(n = =2){ -vis[a[1] + a[2]] =1; -         } the         Else{ -vis[a[1] + a[2]] =1; -vis[a[2] + a[3]] =1; -vis[a[1] + a[3]] =1; +vis[a[1] + a[2] + a[3]] =1; -         } +          for(i =1;; i++) A         if(!Vis[i]) { atcout << i <<Endl; -              Break; -         } -     } -     return 0; -}
View Code

In fact, many simple, is test instructions too pit has wood has ~ ~ ~

[Swust OJ 234]--irreduciblenumber (test instructions Tai Keng)

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.