当前位置:网站首页>码蹄集 万民堂大厨
码蹄集 万民堂大厨
2022-07-25 22:47:00 【Elvin域文】
运行时错误:
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
vector<vector<long long int>> res;
vector<long long int> arr2;
long long int target;
long long int start,last=0;
vector<long long int> temp;
long long int tim=0;
int OK(vector<long long int>a,long long int k,long long int i)//判断是否有重复元素
{
if(i>k)//保证数组存在的时候
for(int t=k;t<i;t++)//循环查找
{
if(a[t]==a[i])
return 0;
}
return 1;
}
void Perm(vector<long long int>a,long long int k,long long int m)//全排列的实现函数
{
if(k==m)//只剩下1个元素
{
tim++;//次数+1
// for(int i=0;i<=m;i++)
// {
// cout<<a[i];
// }
// cout<<"\n";
}
else //还有多个元素待排列
{
for(int i=k;i<=m;i++)//有几个元素就循环几次(因为以它打头,然后对后面的数进行全排列)
{
if(OK(a,k,i))//当不存在重复元素的时候,才进行全排列
{
swap(a[k],a[i]);//进行交换
Perm(a,k+1,m);
swap(a[k],a[i]);
}
}
}
}
int helper(vector<long long int> arr, long long int target, vector<long long int> arr2, long long int index){
if(target==0)
{
res.insert(res.end(),arr2);
}
for(int i=index; i<arr.size();i++){
if(arr[i] <= target){
arr2.insert(arr2.end(),arr[i]);
helper(arr, target-arr[i], arr2, i);
arr2.pop_back();
}
}
}
vector<vector<long long int>> combinationSum(vector<long long int> arr, long long int target){
helper(arr, target, arr2, 0);
return res;
}
int main()
{
vector<long long int> arr; //原始数组
long long int n,m,k,x;
cin >> x >> n >> m >> k;
target = x;
arr.insert(arr.end(),n);
arr.insert(arr.end(),m);
arr.insert(arr.end(),k);
combinationSum(arr,target);
for(int i=0;i<res.size();i++){
for(int j=0;j<res[i].size();j++){
start = 0;
temp.insert(temp.end(), res[i][j]);
}
last = res[i].size()-1;
Perm(temp, start, last);
temp.clear();
}
if(tim){
cout << tim%mod;
}
else{
cout << "impossible";
}
// cout << "组成的数量为:" << tim ;
return 0;
}边栏推荐
- Short circuit effect of logical operators short circuit and short circuit or
- Extended configuration of static routing in the second experiment
- 【集训DAY12】Bee GO!【动态规划】【数学】
- Experiment 1, experiment 2 and Experiment 3 of assembly language and microcomputer principle: branch program design / loop program design / subroutine design
- Common software shortcuts
- Vs2017 compilation encountered the error HResult e returned by the call of COM component_ FAIL
- 贴片微型滚珠振动开关的结构原理
- Simple setting of drop-down triangle
- MySQL data type
- [training day13] travel [violence] [dynamic planning]
猜你喜欢

Simple setting method of search box

我们为什么要推出Getaverse?

3 lexical analysis

recyclerview计算滑动距离之computeHorizontalScrollExtent-computeHorizontalScrollRange-computeHorizontalScrol

Multi data source switching

Day006 select structure (if statement exercise)

Extended configuration of static routing in the second experiment

Session and cookie, token and storage
![[training day13] backpack [dynamic planning] [greed]](/img/a7/3df395d84f510dea8b42ebcc4ff5f2.png)
[training day13] backpack [dynamic planning] [greed]

(1) Integrating two mapping frameworks of Dao
随机推荐
【集训DAY12】X equation 【高精度】【数学】
ORM common requirements
QT log file system
[MySQL rights] UDF rights (with Malaysia)
Multi data source switching
Binder principle
Understanding of forward proxy and reverse proxy
[training day13] backpack [dynamic planning] [greed]
Kibana~ the process number cannot be found after kibana is started in the background
Deep recursion, deep search DFS, backtracking, paper cutting learning.
XSS collect common code
[natural language processing] [vector representation] augsbert: improve the data enhancement method of Bi encoders for paired sentence scoring tasks
[training day15] good name [hash]
[文献阅读] - HRL -[HRL with Universal Policies for Multi-Step Robotic Manipulation]
Array中可以用泛型吗
Builder pattern
Interpretation of English terms
Floating effect and characteristics
Compiler introduction
Why is Google's internal tools not suitable for you?