当前位置:网站首页>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;
}
边栏推荐
- 文献调研(一):基于集成学习和能耗模式分类的办公楼小时能耗预测
- Two ways to center block level elements
- static关键字详解
- Establishment of multiple background blocks in botu software_ Old bear passing by_ Sina blog
- On the quantity control mechanism of swoole collaboration creation in production environment
- Use Baidu map API to set an overlay (infowindow) in the map to customize the window content
- 如何配置SQL Server 2008管理器_过路老熊_新浪博客
- Summary of c++ references and pointers
- Apache doris1.0 cluster setup, load balancing and parameter tuning
- Record a simple question with ideas at the moment of brushing leetcode - Sword finger offer 09 Implementing queues with two stacks
猜你喜欢

SSM integrated learning notes (mainly ideas)

Common problems encountered when creating and publishing packages using NPM

文献调研(三):数据驱动的建筑能耗预测模型综述

STEP7主站与远程I/O组网_过路老熊_新浪博客

iomanip头文件在实战中的作用

Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
![搜索旋转数组II[抽象二分练习]](/img/db/3ea01cf1ad8446a7007891ef1d8e7f.png)
搜索旋转数组II[抽象二分练习]

Literature research (II): quantitative evaluation of building energy efficiency performance based on short-term energy prediction

DNS复习
![寻找翻转数组的最小值[抽象二分]](/img/b9/1e0c6196e6dc51ae2c48f6c5e83289.png)
寻找翻转数组的最小值[抽象二分]
随机推荐
Final and static
Alipay payment interface sandbox environment test and integration into an SSM e-commerce project
Stream in PHP socket communication_ Understanding of select method
Stop eating vitamin C tablets. These six fruits have the highest vitamin C content
支付宝支付接口沙箱环境测试以及整合到一个ssm电商项目中
说说单例模式!
关于运行scrapy项目时提示 ModuleNotFoundError: No module named 'pymongo‘的解决方案
手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客
Let's talk about string today
SSM整合学习笔记(主要是思路)
JS中的数字数组去重
static关键字详解
[reprint]rslogix 5000 instance tutorial
step7和wincc联合仿真_过路老熊_新浪博客
详细讲解局部变量、全局变量、静态变量三种类型
Common problems encountered when creating and publishing packages using NPM
The InputStream stream has been closed, but the file or folder cannot be deleted, indicating that it is occupied by the JVM
huibian
Backup restore of xtrabackup
Shredding Company poj 1416