当前位置:网站首页>Shredding Company poj 1416
Shredding Company poj 1416
2022-06-25 22:10:00 【AMjieker】
Shredding Company
解题思路 : 暴搜 dfs
用两个字符串存储目标和剪切串
利用stl
的string
的substr
截取k
到l
然后转换成数字填入一个vector
数组中,枚举出来的每一种方案都存到map<int,vector< int> >
中 顺便纪录一下ans
和ansf
ansf
代表着重复次数
代码:
#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;
}
边栏推荐
- Format the number. If the number is not enough, fill in 0, for example, 1:0001,25:0025
- 兆欧表电压档位选择_过路老熊_新浪博客
- 4个要点,助力产品管好项目
- Uniapp - call payment function: Alipay
- WordPress
- 在win10下使用visual studio2015链接mysql数据库
- 说说单例模式!
- line-height小用
- Leetcode 513. 找树左下角的值
- The simplest screen recording to GIF gadget in history, licecap, can be tried if the requirements are not high
猜你喜欢
Final and static
STL教程5-STL基本概念及String和vector使用
Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
使用npm创建并发布包时遇到的常见问题
实例:用C#.NET手把手教你做微信公众号开发(21)--使用微信支付线上收款:H5方式
How does excel translate Chinese words into English automatically? This formula teaches you
解析产品开发失败的5个根本原因
Alipay payment interface sandbox environment test and integration into an SSM e-commerce project
权限设计=功能权限+数据权限
CXF
随机推荐
搜索旋转数组II[抽象二分练习]
51 single chip microcomputer, some registers, some knowledge points
Raspberry pie sends hotspot for remote login
Object类常用方法
Final and static
JS中的数字数组去重
mysql5.7版本在配置文件my.ini[mysqld]加上skip-grant-tables后无法启动
Leetcode-1528- rearrange string - hash table - string
line-height小用
博图软件中多重背景块的建立_过路老熊_新浪博客
OpenResty篇01-入门简介和安装配置
static关键字详解
动态验证码
Uniapp -- the use of document collation and push of unipush
数据同步
Database - mongodb
MySQL InnoDB锁知识点
Leetcode 513. 找树左下角的值
Blob
今天说说String相关知识点