poj1936 All in All

All in All
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 31754 Accepted: 13179

Description

You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string. 

Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s. 

Input

The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace.The length of s and t will no more than 100000.

Output

For each test case output "Yes", if s is a subsequence of t,otherwise output "No".

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No
比较简单,只要第二个串中第一个串的字符相对顺序不变就可以。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
   char s[100005],t[100005];
   while(~scanf("%s%s",s,t))
   {
       int i,j;
       j=0;
       int l=strlen(t);
       for(i=0;i<l;++i)
       {
           if(t[i]==s[j])
           {
               j++;
               if(s[j]=='\0')break;
           }
       }
       if(i<l)printf("Yes\n");
       else printf("No\n");
   }
    return 0;
}

直接走一遍就可以了~


### 关于 POJ 2456 的问题分析 POJ 平台上的题目通常涉及算法设计、数据结构应用以及复杂度优化等问题。虽然未提供具体关于 POJ 2456 题目的直接描述,但从其他类似题目的解决方法可以推测其可能的解决方案。 #### 差分约束系统的应用 如果 POJ 2456 类似于差分约束系统的问题,则可以通过构建图模型并使用 SPFA 算法来寻找最长路径[^3]。在此类问题中,条件 \(A - B \geq X\) 和 \(A - B \leq X\) 可转化为节点间的边权关系,并通过引入超级源点确保整个图连通性。这种方法适用于一系列不等式约束下的变量取值范围判定问题。 #### 动态规划 vs 常规解法对比 针对某些特定类型的题目,动态规划 (Dynamic Programming, DP) 提供了一种高效解决问题的方式,尤其当子问题具有重叠性质时。然而,在实际实现过程中需要注意状态定义合理性及转移方程准确性[^2]。相比之下,传统方法可能会因为重复计算而导致时间效率低下。 以下是基于上述理论的一个简单伪代码框架用于处理此类问题: ```python from collections import deque def spfa(n, edges): dist = [-float('inf')] * n in_queue = [False] * n queue = deque() # 初始化超级源点连接所有顶点 super_source = n new_edges = [(super_source, i, 0) for i in range(n)] all_edges = edges + new_edges dist[super_source] = 0 queue.append(super_source) in_queue[super_source] = True while queue: u = queue.popleft() in_queue[u] = False for v, w in adj_list[u]: if dist[v] < dist[u] + w: dist[v] = dist[u] + w if not in_queue[v]: queue.append(v) in_queue[v] = True # 判断是否有正环存在 if len(queue) > n: return "Positive cycle exists" return max(dist[:n]) # 构建邻接表表示图结构 adj_list = [[] for _ in range(n+1)] for a,b,w in edges: adj_list[a].append((b, w)) ``` 此代码片段展示了如何运用队列维护待访问结点集合并通过松弛操作更新最短距离数组 `dist` 。同时加入了对可能出现的正向循环检测机制。 ### 结论 综上所述,解答 POJ 2456 或相似编号的问题需依据具体需求选取合适的技术手段。无论是采用差分约束还是动态规划策略,都应注重细节把控以提升程序性能表现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值