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
Sample Output
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)