-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduplicate_jarjar.cpp
112 lines (106 loc) · 1.82 KB
/
duplicate_jarjar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long int arr[10006];
int n;
int dp[2000][2000];
set<int>s;
/*long long int arr_sum(long long int data[],int index)
{
long long int ans=0;
for(int i=0;i<index;i++)
{
ans=ans+data[i];
}
return ans;
}*/
int combination(long long int sum,int index,int i)
{
if(dp[sum][index]!=0)
return dp[sum][index];
if(sum==0)
{
cout<<sum<<index<<endl;
return dp[sum][index];
}
/*if(sum==0)
{
/* for(int i=0;i<index;i++)
{
cout<<data[i];
}
cout<<endl;
cout<<ans<< " ";
s.insert(index);
return ;
}*/
if(i>=n)
{
return 0;
//return dp[sum][index];
}
//data[index]=arr[i];
dp[sum][index]=combination(sum-arr[i],index+1,i+1)+1;
dp[sum][index]=combination(sum,index,i+1);
return dp[sum][index];
}
/*void printcombination(long long int sum)
{
// A temporary array to store all combination one by one
long long int data[n];
// Print all combination using temprary array 'data[]'
combination(sum,data,0,0);
}*/
int main()
{
freopen("test.txt","r",stdin);
int q;
while(scanf("%d %d",&n,&q))
{
if(n==0 && q==0)
{
break;
}
for(int i=0;i<n;i++)
{
scanf("%lld",&arr[i]);
}
while(q--)
{
long long int sum;
scanf("%lld",&sum);
//s.clear();
for(int i=0;i<=n;i++)
{
for(int j=0;j<=n;j++)
{
dp[i][j]=0;
}
}
combination(sum,0,0);
for(int i=0;i<=n;i++)
{
for(int j=0;j<=n;j++)
{
cout<<dp[i][j]<< " ";
}
cout<<endl;
}
cout<<endl;
/*set<int>::iterator i;
if(!s.empty())
{
for(i=s.begin();i!=s.end();i++)
{
cout<<*i<<" ";
}
cout<<endl;
}
else
{
cout<<"Not possible"<<endl;
}*/
}
}
return 0;
}