HDU 6092 Rikka with Subset

Rikka with Subset

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 739    Accepted Submission(s): 352


 

Sample Input
2
2 3
1 1 1 1
3 3
1 3 3 1
Sample Output
1 2
1 1 1
Hint
In the first sample, $A$ is $[1,2]$. $A$ has four subsets $[],[1],[2],[1,2]$ and the sums of each subset are $0,1,2,3$. So $B=[1,1,1,1]$
 

 

Source
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cctype> 
 5 #include<cmath>
 6 #include<cstring>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<vector>
11 #include<algorithm>
12 #include<string> 
13 #define ll long long
14 #define eps 1e-10
15 #define LL unsigned long long
16 using namespace std; 
17 const int inf=0x3f3f3f3f;
18 const int maxn=10000+10;
19 const int mod=1e9+7;
20 int a[maxn],b[maxn];
21 int main()
22 {
23     int t,n,m;
24     scanf("%d",&t);
25     while(t--)
26     {
27         memset(a,0,sizeof(a));
28         scanf("%d%d",&n,&m);
29         for(int i=0;i<=m;i++)scanf("%d",&b[i]);
30         for(int i=1;i<=n;i++){
31             int flag=0;
32             for(int j=1;j<=m;j++){
33                 if(b[j]==0)continue;
34                 if(b[j]&&flag==0){
35                     flag=1;
36                     a[i]=j;
37                 }
38                 b[j]=b[j]-b[j-a[i]];
39             }
40         }
41         for(int i=1;i<=n;i++)
42         printf("%s%d",i==1?"":" ",a[i]);
43         printf("\n");
44     }
45     return 0;
46 }

 

 

posted on 2017-08-08 22:16  见字如面  阅读(199)  评论(0编辑  收藏  举报

导航