1 solutions

  • 0
    @ 2025-3-3 16:28:35

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int n,b[10101],z;
    void work(int d,int s)
    {
    	if(s==z)
    	{
    		cout<<"YES";
    		exit(0);
    	}
    	if(d>n)
    	{
    		return;
    	}
    	for(int i=1;i<=n;i++)
    	{
    		work(d+1,s);
    		work(d+1,s+b[i]);
    	}
    }
    int main()
    {
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>b[i];
    	}
    	cin>>z;
    	work(1,0);
    	cout<<"NO";	
    	return 0;
    }
    
    
    • 1

    Information

    ID
    10216
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By