Thanks for your answers.
I've finally solve this problem.
I've created two arrays:
bool wasadd[2 000 001]
and
int sums[2 000 001]
It's "only"

2 000 000 possible sums.
I show my algorithm using example:
Set: 2,3,4 Sum to find: 7
wassadd[2+1 000 000] = 1;
sums[0] = 2;
Code: Select all
for members of set from 3 to 4 do
for every integer in sums array:
if (wassad[sums[x]+actual member of set+ 1 000 000]==0)
add sums[x]+actual member to sums array
wassad[sums[x]+actual member of set+ 1 000 000]=1
if (wassad[sumtofind + 1 000 000]==1) i can find sum in this set
State of arrays sums and wasadd for each step of algoritm
Fristly
wassad: 1 000 002 are "1"
sums: 2
Actual member of set - 3
wassad: 1 000 002, 1 000 003, 1 000 005 are "1"
sums: 2, 3, 5
Aktual member of set - 4
wassad: 1 000 002, 1 000 003, 1 000 005, 1 000 004, 1 000 006, 1 000 007, , 1 000 009 are "1"
sums: 2, 3, 5, 4, 6, 7, 9
1 000 007 is "1" so I can find subset which sum is 7
I hope you understand
