B - Two-gram

Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.

You are given a string ss consisting of nn capital Latin letters. You

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<iostream>
using namespace std;
int main()
{
    int n,i,j;string s;
    scanf("%d",&n);
    getchar();
    cin>>s;
    int dp[100][100]={0};   ///利用二维数组来做;
    for(i=0;i<n-1;i++)
    {
        int x=s[i]-'A';
        int y=s[i+1]-'A';
        dp[x][y]++;     ///利用dp[x][y],看谁出现的次数多,就值要大。
    }
    int mat=0,last=0,next=0;
    for(i=0;i<26;i++)
    {
        for(j=0;j<26;j++)
        {
            if(mat<dp[i][j])
            {
                last=i;next=j;
                mat=dp[i][j];
            }
        }
    }
    printf("%c%c",last+'A',next+'A');
}

解题思路:由于可以迭代去看,然后我们就用一个二维数组来保存那两个连续出现的字母出现的次数。至于用二维数组的那两个下标代表什么?就是代表那两个连续的字母

 

 

r task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string ss = "BBAABBBA" the answer is two-gram "BB", which contained in ss three times. In other words, find any most frequent two-gram.

Note that occurrences of the two-gram can overlap with each other.

Input

The first line of the input contains integer number nn (2≤n≤1002≤n≤100) — the length of string ss. The second line of the input contains the string ss consisting of nn capital Latin letters.

Output

Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string ss as a substring (i.e. two consecutive characters of the string) maximal number of times.

Examples

Input

7
ABACABA

Output

AB

Input

5
ZZZAA

Output

ZZ

Note

In the first example "BA" is also valid answer.

In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.

### 风格一致性损失的概念与实现 风格一致性损失是一种用于确保生成图像在多个尺度上保持一致性的技术。它通常被应用于神经风格迁移领域,目的是解决传统风格迁移方法可能产生的不连贯或失真的问题。 #### 1. 风格一致性损失的作用 风格一致性损失的核心在于减少多尺度下风格特征的变化,从而使生成的图像更加自然和谐[^1]。具体来说,在传统的风格迁移过程中,仅依赖单尺度的风格损失可能会导致局部区域间的风格冲突或者边界模糊等问题。而引入风格一致性损失可以有效缓解这些问题。 #### 2. 计算方式 为了计算风格一致性损失,可以通过以下几种常见的方式: - **跨层约束** 使用来自不同卷积层的特征图来定义额外的一致性项。例如,假设 \(L_{style}\) 表示标准的风格损失,则可以在相邻两层之间增加一项惩罚因子 \(\Delta L\) 来表示它们之间的偏差程度: \[ L_{consistency} = ||G(F^{l}) - G(F^{l+1})||_F^2 \] 这里 \(G(\cdot)\) 是 Gram 矩阵操作符,\(F^{l}, F^{l+1}\) 分别代表第 l 层和第 (l+1) 层提取到的特征向量。 - **金字塔结构** 构建一个多分辨率的图像金字塔,并针对每一级执行独立却相互关联的优化过程。最终将各级别的结果组合起来形成完整的输出图片。这种方法能够很好地维持全局布局的同时兼顾细节表现力。 #### 3. 实现代码示例 以下是基于 PyTorch 的简单实现片段,展示了如何构建并应用上述提到的一种形式化表达——即通过比较两个连续层次间 gram matrix 差异大小来进行控制: ```python import torch from torchvision import models def compute_gram_matrix(feature_map): """Compute the Gram Matrix of a given feature map.""" b, c, h, w = feature_map.size() features = feature_map.view(b * c, h * w) gram = torch.mm(features, features.t()) / (b * c * h * w) return gram class StyleConsistencyLoss(torch.nn.Module): def __init__(self): super(StyleConsistencyLoss, self).__init__() def forward(self, prev_features, curr_features): """ Calculate style consistency loss between two consecutive layers' activations. Args: prev_features: Tensor representing previous layer's activation maps. curr_features: Tensor representing current layer's activation maps. Returns: Scalar tensor containing computed loss value. """ prev_gram = compute_gram_matrix(prev_features) curr_gram = compute_gram_matrix(curr_features) diff = ((prev_gram - curr_gram)**2).mean() # Mean squared error over all elements return diff ``` 此模块可以直接嵌入至任何现有的神经艺术转换框架之中作为附加组件之一参与整体目标函数的设计当中去。 #### 4. 推荐资源 对于希望深入研究该主题的学习者,《PyTorch深度学习与计算机视觉实践》是一本非常有价值的参考资料[^2]。书中不仅涵盖了基础理论知识还提供了丰富的实际案例分析以及详尽的操作指南帮助初学者快速入门并掌握相关技能要点。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值