Rikka with Subset

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


Problem Description

As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Yuta has n.

It is too difficult for Rikka. Can you help her?  

 

 

Input

The first line contains a number ).

 

 

Output

For each testcase, print a single line with n.

It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.

 

 

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]$

 

//题意:给出 n,m 代表有 n 个数,和为 m ,设为数列 a[i],将 a[i] 的所有子集,的和求出,记录种数,得到 b[i] ,现给出 b ,求 a

 

//还是太水了,这种题竟然没有一点思路,01背包的反向做法即可推出 a ,具体做法是先找到最小的不为0的 b[i] ,i 即为 a 中最小的,然后,b[j]-=b[j-i] , O(n*m)

 1 # include <cstdio>
 2 # include <cstring>
 3 # include <cstdlib>
 4 # include <iostream>
 5 # include <vector>
 6 # include <queue>
 7 # include <stack>
 8 # include <map>
 9 # include <bitset>
10 # include <set>
11 # include <cmath>
12 # include <algorithm>
13 using namespace std;
14 #define lowbit(x) ((x)&(-x))
15 #define pi acos(-1.0)
16 #define eps 1e-8
17 #define MOD 1000000007
18 #define INF 0x3f3f3f3f
19 #define LL long long
20 inline int scan() {
21     int x=0,f=1; char ch=getchar();
22     while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
23     while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
24     return x*f;
25 }
26 inline void Out(int a) {
27     if(a<0) {putchar('-'); a=-a;}
28     if(a>=10) Out(a/10);
29     putchar(a%10+'0');
30 }
31 #define MX 100005
32 //Code begin...
33 int dp[MX];
34 
35 int main()
36 {
37     int t = scan();
38     while (t--)
39     {
40         int n = scan(),m = scan();
41         dp[0]=1;
42         for (int i=0;i<m+1;i++)
43             dp[i] = scan();
44 
45         vector<int> ans;
46         for (int i=1;i<=n;i++)
47         {
48             int k;
49             for (int j=1;j<=m;j++)
50             if (dp[j]!=0)
51             {
52                 k = j;
53                 ans.push_back(k);
54                 break;
55             }
56             for (int j=k;j<=m;j++)
57                 dp[j] -= dp[j-k];
58 
59         }
60         for (int i=0;i<n;i++)
61             printf("%d%c",ans[i],i!=n-1?' ':'\n');
62     }
63     return 0;
64 }
View Code

相关文章:

  • 2021-05-15
  • 2022-12-23
  • 2022-02-07
  • 2021-07-08
  • 2021-06-13
  • 2021-05-18
  • 2021-06-11
  • 2021-07-02
猜你喜欢
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
相关资源
相似解决方案