当前位置:网站首页>Shredding Company poj 1416
Shredding Company poj 1416
2022-06-26 00:03:00 【AMjieker】
Shredding Company
Their thinking : Violent search dfs
Use two strings to store the target and cut string
utilizestlOfstringOfsubstrInterceptkTolThen convert it into numbers and fill in avectorArray , Each of the enumerated schemes is stored inmap<int,vector< int> >in By the wayansandansfansfRepresents the number of repetitions
Code :
#include<iostream>
#include<map>
#include<vector>
#define int long long
using namespace std;
string a,b;
int ai,bi;
int ans,ansf;
map<int,vector<int> > mp;
vector<int> d;
inline int toint(string s){
int tt(0);
for(int i=0;i<s.size();i++) tt=tt*10+s[i]-'0';
return tt;
}
void dfs(int k,int v){
if(v>ai) return;
if(k==b.size()){
if(ans<v){
ans = v,ansf = 0;
for(int i=0;i<d.size();i++)
mp[ans].push_back(d[i]);
}else if(ans==v){
ansf++;
}
return;
}
int i(1);
while(k+i<=b.size()){
int t = toint(b.substr(k,i));
if(t+v>ai) break;
d.push_back(t);
dfs(k+i,t+v);
d.pop_back();
i++;
}
}
signed main(){
while(cin>>a>>b&&a!="0"&&b!="0"){
ai = toint(a);
bi = toint(b);
if(ai==bi) {
cout<<a<<" "<<b<<endl;
// }else if(ai>bi){
// cout<<"error"<<endl;
}else{
d.clear();
mp.clear();
ans = 0;
ansf = 0;
dfs(0,0);
if(ansf){
cout<<"rejected"<<endl;
}else if(ans!=0){
cout<<ans;
for(int i=0;i<mp[ans].size();i++){
cout<<" "<<mp[ans][i];
}
cout<<endl;
}else{
cout<<"error"<<endl;
}
}
}
return 0;
}
边栏推荐
- 博图软件中多重背景块的建立_过路老熊_新浪博客
- php进程间传递文件描述符
- 给定参数n,从1到n会有n个整数1,2,3,...,n,这n个数组共有n!种排列,按照大小顺序升序排列出所有列的情况,并一一标记,给定n和k,返回第k个值
- Unsigned and signed vernacular
- line-height小用
- Backup restore of xtrabackup
- iomanip头文件在实战中的作用
- Bit Compressor [蓝桥杯题目训练]
- Problems encountered in Doris operation and maintenance
- Simulation connection between WinCC and STEP7_ Old bear passing by_ Sina blog
猜你喜欢

文獻調研(三):數據驅動的建築能耗預測模型綜述

如何配置SQL Server 2008管理器_过路老熊_新浪博客

C ++ 引用与指针总结

Lazy people teach you to use kiwi fruit to lose 16 kg in a month_ Old bear passing by_ Sina blog

手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客

推荐系统设计

How to configure SQL Server 2008 Manager_ Old bear passing by_ Sina blog

Circuit de fabrication manuelle d'un port série de niveau USB à TTL pour PL - 2303hx Old bear passing Sina blog

Establishment of multiple background blocks in botu software_ Old bear passing by_ Sina blog

Studio5k v28安装及破解_过路老熊_新浪博客
随机推荐
Recherche documentaire (3): examen des modèles de prévision de la consommation d'énergie des bâtiments fondés sur les données
Analyse des cinq causes profondes de l'échec du développement de produits
Transformation of communication protocol between Siemens S7-200PLC and Danfoss inverter_ Old bear passing by_ Sina blog
文獻調研(三):數據驅動的建築能耗預測模型綜述
Find the minimum value of flipped array [Abstract bisection]
用ES5的方式实现const
Establishment of multiple background blocks in botu software_ Old bear passing by_ Sina blog
详解synchronize关键字
Oracle writes a trigger that inserts a piece of data first and updates a field in the data
Search rotation array ii[Abstract dichotomy exercise]
php socket通信中stream_select方法的理解
Keil compilation run error, missing error: # 5: # includecore_ cm3.h_ Old bear passing by_ Sina blog
手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客
ASA如何配置端口映射及PAT
Record a simple question with ideas at the moment of brushing leetcode - Sword finger offer 09 Implementing queues with two stacks
Backup restore of xtrabackup
Topic36——53. 最大子数组和
Static keyword explanation
对象数组去重
iomanip头文件在实战中的作用