1045. Favorite Color Stripe (30)

2 篇文章 0 订阅
1 篇文章 0 订阅

Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to form her favorite color stripe.


It is said that a normal human eye can distinguish about less than 200 different colors, so Eva's favorite colors are limited. However the original stripe could be very long, and Eva would like to have the remaining favorite stripe with the maximum length. So she needs your help to find her the best result.
Note that the solution might not be unique, but you only have to tell her the maximum length. For example, given a stripe of colors {2 2 4 1 5 5 6 3 1 1 5 6}. If Eva's favorite colors are given in her favorite order as {2 3 1 5 6}, then she has 4 possible best solutions {2 2 1 1 1 5 6}, {2 2 1 5 5 5 6}, {2 2 1 5 5 6 6}, and {2 2 3 1 1 5 6}.


Input Specification:


Each input file contains one test case. For each case, the first line contains a positive integer N (<=200) which is the total number of colors involved (and hence the colors are numbered from 1 to N). Then the next line starts with a positive integer M (<=200) followed by M Eva's favorite color numbers given in her favorite order. Finally the third line starts with a positive integer L (<=10000) which is the length of the given stripe, followed by L colors on the stripe. All the numbers in a line are separated by a space.


Output Specification:


For each test case, simply print in a line the maximum length of Eva's favorite stripe.


Sample Input:
6
5 2 3 1 5 6
12 2 2 4 1 5 5 6 3 1 1 5 6
Sample Output:

7

算法思路:类似LCS问题

<img src="http://latex.codecogs.com/gif.latex?dp[i%20+%201][j%20+%201]%20=%20\left\{%20{\begin{array}{*{20}{c}}%20{dp[i][j]%20+%201,({s_i}%20=%20{t_j})}\\%20{\max%20(dp[i][j%20+%201],dp[i%20+%201][j]),\mbox{if%20other}}%20\end{array}}%20\right\}
" />

#include<stdio.h>
#define MAX 205
int like[MAX];
int strip[10005];
int lcs[MAX][10005];
int main(){
    int N,M,L;
    scanf("%d",&N);
    scanf("%d",&M);
    for(int i=0;i<M;i++)
        scanf("%d",&like[i]);
    scanf("%d",&L);
    for(int i=0;i<L;i++)
        scanf("%d",&strip[i]);
    for(int i=0;i<M;i++){
        for(int j=0;j<L;j++){
            if(like[i]==strip[j]){
                //区别于LCS解法lcs[i+1][j+1]=lcs[i][j]+1;
                lcs[i+1][j+1]=lcs[i+1][j]+1;
            }else
                lcs[i+1][j+1]=lcs[i][j+1]>lcs[i+1][j]?lcs[i][j+1]:lcs[i+1][j];
        }
    }
    printf("%d",lcs[M][L]);
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好! 有关Stripe的Java开发,我可以为您提供一些信息。 Stripe是一家提供在线支付解决方案的公司,他们的Java库使您能够在您的Java应用程序中集成Stripe支付功能。使用Stripe Java库,您可以轻松地创建和管理付款、订阅和退款,处理信用卡支付等。 要开始使用Stripe Java库,您需要在您的项目中添加Stripe的依赖项。您可以在Maven或Gradle构建工具中添加相应的依赖项。例如,在Maven项目中,您可以将以下内容添加到您的pom.xml文件中: ```xml <dependency> <groupId>com.stripe</groupId> <artifactId>stripe-java</artifactId> <version>19.64.0</version> </dependency> ``` 一旦您添加了依赖项,就可以使用Stripe Java库的各种功能来处理支付事务。您需要设置您的Stripe API密钥,并使用该密钥进行身份验证。然后,您可以使用库提供的方法来创建付款、订阅、退款等。 以下是一个简单的示例,展示了如何使用Stripe Java库创建一个付款: ```java import com.stripe.Stripe; import com.stripe.model.Charge; import com.stripe.param.ChargeCreateParams; public class StripeExample { public static void main(String[] args) { // 设置您的Stripe API密钥 Stripe.apiKey = "YOUR_STRIPE_API_KEY"; // 创建付款参数 ChargeCreateParams params = ChargeCreateParams.builder() .setAmount(1000) .setCurrency("usd") .setDescription("Example payment") .setSource("tok_visa") .build(); // 创建付款 try { Charge charge = Charge.create(params); System.out.println("Payment successful! Charge ID: " + charge.getId()); } catch (Exception e) { System.out.println("Payment failed: " + e.getMessage()); } } } ``` 请注意,您需要将"YOUR_STRIPE_API_KEY"替换为您自己的Stripe API密钥。 以上是一个简单的示例,用于说明如何使用Stripe Java库进行付款。您可以根据自己的需求使用不同的方法和参数来处理其他类型的支付事务。 希望以上信息对您有所帮助!如果您有任何其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值