CF156C Cipher

cf传送门
题意
给定一个只由小写字母组成的字符串
可以将相邻两位分别 + 1 +1 +1 − 1 -1 1 − 1 -1 1 + 1 +1 +1,但不能超出小写字母范围
问共能变换多少种字符串。
思路
a a a ~ z z z换成 0 0 0 ~ 25 25 25
发现无论怎样变换,总和不变
考虑 D P DP DP f [ i ] [ j ] f[i][j] f[i][j]表示字符串长度为 i i i,总和为 j j j的方案数
预处理 f f f数组
每次询问时输出即可

下面是java中的加密解密方法,写出对应的前端加密解密方法 public static String encryptAES(String plainText, String base64Key) { try { byte[] keyBytes = Base64.getDecoder().decode(base64Key); SecretKeySpec key = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] iv = cipher.getIV(); byte[] cipherText = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8)); byte[] combined = new byte[iv.length + cipherText.length]; System.arraycopy(iv, 0, combined, 0, iv.length); System.arraycopy(cipherText, 0, combined, iv.length, cipherText.length); return Base64.getEncoder().encodeToString(combined); } catch (Exception e) { throw new RuntimeException("Encrypted failed. ", e); } } /** * * @param encryptedText * @param base64Key * @return */ public static String decryptAES(String encryptedText, String base64Key) { try { byte[] combined = Base64.getDecoder().decode(encryptedText); byte[] iv = Arrays.copyOfRange(combined, 0, 16); byte[] cipherText = Arrays.copyOfRange(combined, 16, combined.length); byte[] keyBytes = Base64.getDecoder().decode(base64Key); SecretKeySpec key = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); byte[] plainText = cipher.doFinal(cipherText); return new String(plainText, StandardCharsets.UTF_8); } catch (Exception e) { throw new RuntimeException("Decrypted failed. ", e); } }
03-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值