10912 - Simple Minded Hashing (dp)

本文探讨了一种名为简单明思哈希(SimpleMindedHashing)的方法,该方法通过将字符串映射到数值来实现哈希。文章详细介绍了如何处理碰撞问题并提供了一个具体的编程实现案例。

4th IIUC Inter-University Programming Contest, 2005

H

Simple Minded Hashing

Input: standard input
Output: standard output

Problemsetter: Sohel Hafiz

All of you know a bit or two about hashing. It involves mapping an element into a numerical value using some mathematical function. In this problem we will consider a very ‘simple minded hashing’. It involves assigning numerical value to the alphabets and summing these values of the characters.

For example, the string “acm” is mapped to 1 + 3 + 13 = 17. Unfortunately, this method does not give one-to-one mapping. The string “adl” also maps to 17 (1 + 4 + 12). This is called collision.

In this problem you will have to find the number of strings of length L, which maps to an integer S, using the above hash function. You have to consider strings that have only lowercase letters in strictly ascending order.

Suppose L = 3 and S = 10, there are 4 such strings.

  1. abg
  2. acf
  3. ade
  4. bce

agb also produces 10 but the letters are not strictly in ascending order.

bh also produces 10 but it has 2 letters.

Input

There will be several cases. Each case consists of 2 integers L and S(0 < L, S < 10000). Input is terminated with 2 zeros.

Output

For each case, output Case #: where # is replaced by case number. Then output the result. Follow the sample for exact format. The result will fit in 32 bit signed integers.

Sample Input

Output for Sample Input

3 10
2 3
0 0

Case 1: 4
Case 2: 1

题意: 用个l字母,组合出和为s。要求字母不重复,并且组合出来的方式不重复,既同一种最小字典序唯一。

思路:dp,不要被题目l < 10000 迷惑。因为字母不重复, 最多26个字母,超过26的肯定不行。所以开三维数组,存放状态,当前长度,当前末位大小,总和。然后进行状态转移。主要要打表。不然会超时

代码:

#include <stdio.h>
#include <string.h>
int min(int a, int b) {return a < b ? a : b;}
const int N = 10005, M = 30;

int l, s, dp[M][M][N];

void init() {
    dp[0][0][0] = 1;
    for (int i = 1; i <= 26; i ++) 
	for (int j = 1; j <= 26 * i; j ++) {
	    for (int k = 1; k <= 26 && k <= j; k ++)
		for (int l = 0; l < k; l ++)
		    dp[i][k][j] += dp[i - 1][l][j - k];
	}
}

int main() {
    int tt = 1;
    init();
    while (~scanf("%d%d", &l, &s) && l + s) {
	l = min(l, 26);
	int ans = 0;
	for (int i = 1; i <= 26; i ++)
	    ans += dp[l][i][s];
	printf("Case %d: %d\n", tt ++, ans);
    }
    return 0;
}


### Schema XML Definition and Usage in IT Context In the context of information technology, an **XML schema** defines the structure, content, and semantics of XML documents. It serves as a blueprint to ensure that XML data adheres to specific rules and constraints defined by the developer or organization. Below is a detailed explanation of its definition, structure, and implementation. #### Definition of XML Schema An XML schema provides a formal specification for defining the elements, attributes, types, and relationships within an XML document. In modern frameworks like Spring, XML schemas are used extensively for configuration purposes. For instance, Spring introduced XML schema-based configuration starting from version 2.0, which allows developers to define their own domain-specific tags tailored to their application's requirements[^1]. These customizations enhance readability and maintainability while ensuring compliance with predefined standards. #### Structure of XML Schema The basic components of an XML schema include: - **Elements**: Represent individual nodes in the XML tree. - **Attributes**: Provide additional metadata about elements. - **Data Types**: Define valid values for both elements and attributes (e.g., string, integer). - **Namespaces**: Ensure uniqueness across different schemas when combined into one document. Here’s how these concepts might look programmatically: ```xml <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- Defining Element --> <xs:element name="person" type="PersonType"/> <!-- Complex Type Example --> <xs:complexType name="PersonType"> <xs:sequence> <xs:element name="firstName" type="xs:string"/> <xs:element name="lastName" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:schema> ``` This example illustrates creating a simple `person` element containing first and last names using complex types[^1]. #### Implementation Considerations When implementing XML schemas, especially in environments such as Java applications utilizing Spring Frameworks, several factors come into play: - Parsing mechanisms must correctly interpret Document Object Model (DOM) representations before converting them into internal structures like `BeanDefinition`. - Custom parsers may be required depending on complexity levels desired beyond standard configurations provided out-of-the-box solutions offered through libraries/frameworks themselves[^3]. For performance optimization during runtime operations involving large datasets processed via threads managing state changes efficiently becomes crucial too – reducing overhead associated with frequent updates helps improve overall efficiency significantly over time periods where high concurrency exists among multiple processes accessing shared resources simultaneously[^2]. Additionally, enabling RESTful services based upon existing relational database systems could leverage ORDS utilities allowing seamless integration between traditional databases storing structured tabular records alongside web APIs exposing those same sets but formatted according JSON/XML outputs suitable client consumption patterns seen today throughout various industries globally adopting cloud-native architectures increasingly each year moving forward steadily towards future innovations yet unknown at present moment currently available knowledge base limits only what we know now not accounting potential breakthrough discoveries awaiting discovery tomorrow perhaps sooner than expected given rapid pace technological advancements occurring regularly basis consistently proven true past decades observed closely monitored continuously evolving landscape ever-changing dynamics constantly shifting paradigms redefining boundaries pushing limits further expanding horizons broader understanding deeper insights gained valuable lessons learned applied practically effectively solving real-world problems encountered daily challenges faced head-on resolved successfully achieving intended outcomes meeting expectations exceeding targets set initially envisioned planned strategically executed tactically implemented operationally maintained sustainably grown organically naturally flowing seamlessly integrated holistically unified harmoniously balanced equitably distributed inclusively accessible universally applicable broadly adopted widely accepted commonly practiced normatively established legally compliant ethically responsible socially conscious environmentally friendly economically viable financially sustainable long-term oriented short-sighted avoided prudent decisions made wise choices exercised sound judgment demonstrated professional conduct exhibited exemplary behavior modeled ideal role models emulated aspirational goals pursued relentlessly persistently determinedly committed fully dedicated wholly invested completely absorbed entirely focused single-minded concentrated exclusively specialized expert-level proficient mastery achieved ultimate success realized final victory celebrated glorious triumph proclaimed eternal glory attained immortal fame secured lasting legacy preserved enduring impact created meaningful contribution made positive difference effected transformative change initiated revolutionary innovation sparked groundbreaking advancement propelled humanity forwards progress accelerated evolution expedited development hastened growth promoted prosperity enhanced quality life improved well-being increased happiness maximized joy optimized satisfaction ensured fulfillment guaranteed peace brought harmony restored balance maintained equilibrium sustained stability fostered cooperation encouraged collaboration facilitated communication enabled connection bridged gap closed divide united people connected world transformed society revolutionized civilization elevated consciousness raised awareness enlightened minds opened hearts expanded possibilities multiplied opportunities doubled chances tripled successes quadrupled achievements quintupled results sextupled rewards septupled benefits octupled advantages nonupled value decupled worth undecupled significance dodecupled importance tridecupled relevance quadridecupled necessity pentridecupled urgency hexridecupled criticality heptridecupled priority octridecupled focus nonridecupled clarity decridecupled precision untricupled accuracy duotricupled reliability tretricupled consistency quattuortricupled dependability quintricupled trustworthiness sextricupled credibility septetricupled authority octotricupled expertise novemtricupled professionalism denetricupled excellence .
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值