← 返回 coinbase 的题目列表Generate NFT attribute combinations with dedup and weighted random sampling
类型:online_judge
Problem
You are generating NFT metadata. You are given K attribute categories (e.g., Ears, Eyes, Hat), each with a list of candidate values.
Part A: Generate all combinations
Generate all possible combinations by picking exactly one value from each category.
Part B: Dedup
Candidate lists may contain duplicate value strings within the same category. The output combinations must be deduplicated.
Part C: Weighted random generation (follow-up)
Each candidate value has a weight (non-negative int/float). Implement a function to generate one complete combination by independently sampling one value per category according to weights.
Input (stdin)
Line 1: integer K
For each category:
one line: category name name
one line: integer M
next M lines: value weight
Output (stdout)
First print the number of deduplicated combinations for Part A+B
Then print all combinations, one per line, as comma-joined name=value in the input category order
Finally print one line starting with RANDOM: followed by a randomly generated combination (Part C)
Constraints
1 <= K <= 10
1 <= M <= 50
Full enumeration is only tested when the product of per-category unique counts is <= 2*10^5; otherwise only Part C is tested.
Example
Input:
2
Ears
2
Pointy 0.6
Wide 0.4
Eyes
3
Blue 1
Blue 1
Green 2
Output (ordering of combos may vary; random line is not fixed):
4
Ears=Pointy,Eyes=Blue
Ears=Pointy,Eyes=Green
Ears=Wide,Eyes=Blue
Ears=Wide,Eyes=Green
RANDOM: Ears=Wide,Eyes=Green
Example
Input
2
Ears
2
Pointy 0.6
Wide 0.4
Eyes
3
Blue 1
Blue 1
Green 2
Output
4
Ears=Pointy,Eyes=Blue
Ears=Pointy,Eyes=Green
Ears=Wide,Eyes=Blue
Ears=Wide,Eyes=Green
RANDOM: Ears=Pointy,Eyes=Blue