CSU 1354 Distinct subsequences to find different sub-sequences and DP

Source: Internet
Author: User

Topic Link: Click to open the link

Test instructions

Given a long integer

All different sub-sequences and.

Ideas:

Dp[i] denotes the and of the sequence ending with the i number

Num[i] Indicates the number of sequences ending with an I number

Import Java.io.printwriter;import java.util.arraylist;import Java.util.arrays;import Java.util.Collections;import Java.util.comparator;import Java.util.iterator;import Java.util.linkedlist;import Java.util.PriorityQueue;import Java.util.scanner;import Java.util.treeset;import Java.util.queue;public class Main {static int mod = 1000000007;static int N = 100010;long[] dp = new LONG[10], num = new LONG[10]; String s;void work () {int T = Cin.nextint (), while (t--> 0) {s = Cin.next (), int len = S.length (); for (int i = 0; i < 1 0; i++) Dp[i] = Num[i] = 0;for (int i = 0; i < len; i++) {int x = S.charat (i)-' 0 '; Long sum = 0, n = 0;for (int j = 0; J < 1 0; J + +) {sum + = Dp[j];n + num[j];} if (x>0) n++;DP [x] = Sum*10%mod + n*x%mod;num[x] = n%mod;} Long ans = 0;for (int i = 0; i < i++) ans = (ans + dp[i])%mod;out.println (ANS);}} Main () {cin = new Scanner (system.in); out = new PrintWriter (System.out);} public static void Main (string[] args) {main E = new main (); E.work (); Out.close ();} Public ScanneR cin;public static printwriter out;} 


CSU 1354 Distinct subsequences to find different sub-sequences and DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.