uva10564
路径条数很好找。记录最小路径,就记录到各点的最小字符串,存储起来。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF,mod=;
lon n,k,arr[SZ][SZ],dp[SZ][SZ][];
string str[SZ][SZ][]; void init()
{
memset(dp,,sizeof(dp));
for(int i=;i<=*n-;++i)
{
for(lon j=;j<=abs(n-i)+;++j)
{
cin>>arr[i][j];
}
}
for(lon j=;j<SZ;++j)
{
if(j&)dp[][j][]=;
}
} string toStr(lon x)
{
if(x==)return "";
string res="";
for(;x;)
{
res+=''+x%;
x/=;
}
reverse(res.begin(),res.end());
return res;
} bool cmp(const string &x,const string &y)
{
int pos1=x.find(" ");
int pos2=y.find(" ");
if(pos1!=pos2)return pos1<pos2;
else return x<y;
} void work()
{
for(lon i=;i<=*n-;++i)
{
for(lon j=;j<=abs(n-i)+;++j)
{
lon cur=arr[i][j];
for(lon p=arr[i][j];p<=k;++p)
{
if(i<=n)
{
dp[i][j][p]+=dp[i-][j][p-cur];
dp[i][j][p]+=dp[i-][j+][p-cur];
if(i==)
{
str[i][j][p]=toStr(j-)+" ";
}
else if(dp[i-][j][p-cur]&&dp[i-][j+][p-cur])
{
if(cmp(str[i-][j][p-cur],str[i-][j+][p-cur]))
{
str[i][j][p]=str[i-][j][p-cur]+"R";
}
else
{
str[i][j][p]=str[i-][j+][p-cur]+"L";
}
}
else if(dp[i-][j][p-cur])
{
str[i][j][p]=str[i-][j][p-cur]+"R";
}
else if(dp[i-][j+][p-cur])
{
str[i][j][p]=str[i-][j+][p-cur]+"L";
}
}
else
{
dp[i][j][p]+=dp[i-][j-][p-cur];
dp[i][j][p]+=dp[i-][j][p-cur];
if(i==)
{
str[i][j][p]=toStr(j-)+" ";
}
else if(dp[i-][j-][p-cur]&&dp[i-][j][p-cur])
{
if(cmp(str[i-][j-][p-cur],str[i-][j][p-cur]))
{
str[i][j][p]=str[i-][j-][p-cur]+"R";
}
else
{
str[i][j][p]=str[i-][j][p-cur]+"L";
}
}
else if(dp[i-][j-][p-cur])
{
str[i][j][p]=str[i-][j-][p-cur]+"R";
}
else if(dp[i-][j][p-cur])
{
str[i][j][p]=str[i-][j][p-cur]+"L";
}
}
}
}
}
lon res=;
char tmp=(char)(''+);
string minstr="~~~~~~ ";
for(lon j=;j<=n;++j)
{
res+=dp[*n-][j][k];
if(dp[*n-][j][k])
{
//cout<<" "<<str[2*n-1][j][k]<<" "<<(str[2*n-1][j][k]=="")<<endl;
minstr=min(minstr,str[*n-][j][k],cmp);
}
}
cout<<res<<endl;
if(res)cout<<minstr<<endl;
else cout<<endl;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//cout<<casenum<<endl;
//for(lon time=1;time<=casenum;++time)
for(lon time=;cin>>n>>k,n;++time)
{
init();
work();
}
return ;
}
uva10564的更多相关文章
- [置顶] 刘汝佳《训练指南》动态规划::Beginner (25题)解题报告汇总
本文出自 http://blog.csdn.net/shuangde800 刘汝佳<算法竞赛入门经典-训练指南>的动态规划部分的习题Beginner 打开 这个专题一共有25题,刷完 ...
- UVA - 10564 Paths through the Hourglass
传送门:https://vjudge.net/problem/UVA-10564 题目大意:给你一张形如沙漏一般的图,每一个格子有一个权值,问你有多少种方案可以从第一行走到最后一行,并且输出起点最靠前 ...
随机推荐
- topcoder srm 710 div1 -23
1.给定两个长度都为$n$的数组$A,B$,给出一个操作序列将$A$变成$B$.每个操作可以是以下两种之一:(1)选择一个$i,0\leq i <n$且$A_{i} \neq 0$,令$t=A_ ...
- 振兴中华|2013年蓝桥杯A组题解析第三题-fishers
标题: 振兴中华 小明参加了学校的趣味运动会,其中的一个项目是:跳格子. 地上画着一些格子,每个格子里写一个字,如下所示:(也可参见p1.jpg) 从我做起振 我做起振兴 做起振兴中 起振兴中华 比赛 ...
- Spring Boot源码分析
1.核心: SpringApplication.run(SpringbootdemoApplication.class, args); 内部 2.初始化: new SpringApplication( ...
- Web、OAuth2/SSO相关拾遗
OAuth2认证相关:(SSO资源访问流程也应类似设计,它与OAuth2第三方认证.授权不同,是同一个应用系统间的认证.授权过程,且需要实现一个点授权,可访问所有点,一个点退出,收回所有点授权,且有时 ...
- IAR中的 identifier "FILE" is undefined 问题
最近由于希望使用IAR的printf()函数方便进行打印字符,出现IAR报错,即:identifier "FILE" is undefined,问题得以解决. (1)进行pr ...
- 用spring tool suite插件创建spring boot项目时报An internal error occurred during: "Building UI model". com/google/common/
本文为博主原创,未经允许不得转载 在用spring tool suite创建spring boot项目时,报一下异常: 查阅很多资料之后发现是因为装的spring tool suite的版本与ecli ...
- function CONVERSION_EXIT ****INPUT/OUTPUT说明
CONVERSION_EXIT_ALPHA_INPUT和CONVERSION_EXIT_ALPHA_OUTPUT 函数说明 CONVERSION_EXIT_MATN1_INPUT 物料号码转换函数 C ...
- QT移植无法启动 This application failed to start because it could not find or load the QT platform
QT配置好在自己机器上可以运行,但在别人机器上一直弹出 "This application failed to start because it could not find or load ...
- node.js模块本地代理模块(将自己本机/局域网)服务 代理到外网可以访问
npm 模块 localtunnel模块可以. lt --port 7000 其中7000是本地服务端口 会分配一个动态的url. 局域网中查看本地ip用ifconfg 或者在系统偏好设置里面查看网 ...
- centos7 彻底卸载PHP7
[root@xxx php-memcached]# rpm -qa | grep php php70w-common--.w7.x86_64 php70w-devel--.w7.x86_64 php7 ...